Skip to content

Commit

Permalink
Merge pull request #27 from srirams6/master
Browse files Browse the repository at this point in the history
Better file write and format list.
  • Loading branch information
sananth12 committed Mar 4, 2015
2 parents 8e991bd + 13e847a commit 09cc26d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions image_scraper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def get_arguments():
parser.add_argument('--dump-urls', default=False,
help="Print the URLs of the images",
action="store_true")
parser.add_argument('--formats', nargs="*", default=None,
help="sepcify formats in a list without any seperator. This arguent must be after the url.")
parser.add_argument('--scrape-reverse', default=False,
help="Scrape the images in reverse order",
action="store_true")
Expand All @@ -44,7 +46,7 @@ def get_arguments():
save_dir = args.save_dir
download_path = os.path.join(os.getcwd(), save_dir)
use_ghost = args.injected
format_list = ["jpg", "png", "gif", "svg", "jpeg"]
format_list = args.formats if args.formats else ["jpg", "png", "gif", "svg", "jpeg"]
max_filesize = args.max_filesize
dump_urls = args.dump_urls
scrape_reverse = args.scrape_reverse
Expand Down Expand Up @@ -111,9 +113,8 @@ def download_image(img_url, download_path, max_filesize):
return success_flag
if int(img_request.headers['content-length']) < max_filesize:
img_content = img_request.content
f = open(os.path.join(download_path, img_url.split('/')[-1]), 'w')
f.write(img_content)
f.close()
with open(os.path.join(download_path, img_url.split('/')[-1]), 'w') as f:
f.write(img_content)
else:
success_flag = False
size_success_flag = False
Expand Down

0 comments on commit 09cc26d

Please sign in to comment.