Skip to content

Commit

Permalink
reduce message, zfill index
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoongi Kim committed Feb 20, 2019
1 parent a85eda4 commit 7b3bf72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions collect_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def google_full(self, keyword, add_url=""):
time.sleep(1)

links = []
count = 1
# count = 1

last_scroll = 0
scroll_patience = 0
Expand All @@ -173,8 +173,8 @@ def google_full(self, keyword, add_url=""):

if src not in links and src is not None:
links.append(src)
print('%d: %s'%(count, src))
count += 1
# print('%d: %s'%(count, src))
# count += 1

except Exception as e:
print('[Exception occurred while collecting links from google_full] {}'.format(e))
Expand All @@ -191,10 +191,12 @@ def google_full(self, keyword, add_url=""):

elem.send_keys(Keys.RIGHT)

links = set(links)

print('Collect links done. Site: {}, Keyword: {}, Total: {}'.format('google_full', keyword, len(links)))
self.browser.close()

return set(links)
return links

def naver_full(self, keyword, add_url=""):
print('[Full Resolution Mode]')
Expand All @@ -211,7 +213,7 @@ def naver_full(self, keyword, add_url=""):
time.sleep(1)

links = []
count = 1
# count = 1

last_scroll = 0
scroll_patience = 0
Expand All @@ -226,8 +228,8 @@ def naver_full(self, keyword, add_url=""):

if src not in links and src is not None:
links.append(src)
print('%d: %s' % (count, src))
count += 1
# print('%d: %s' % (count, src))
# count += 1

except Exception as e:
print('[Exception occurred while collecting links from naver_full] {}'.format(e))
Expand All @@ -244,9 +246,12 @@ def naver_full(self, keyword, add_url=""):

elem.send_keys(Keys.RIGHT)

links = set(links)

print('Collect links done. Site: {}, Keyword: {}, Total: {}'.format('naver_full', keyword, len(links)))
self.browser.close()

return set(links)
return links


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def download_images(self, keyword, links, site_name):
print('Downloading {} from {}: {} / {}'.format(keyword, site_name, index + 1, total))
response = requests.get(link, stream=True)
ext = self.get_extension_from_link(link)
self.save_image_to_file(response, '{}/{}/{}_{}.{}'.format(self.download_path, keyword, site_name, index, ext))
self.save_image_to_file(response, '{}/{}/{}_{}.{}'.format(self.download_path, keyword, site_name, str(index).zfill(4), ext))
del response

except Exception as e:
Expand Down

0 comments on commit 7b3bf72

Please sign in to comment.