Created
May 21, 2013 22:54
-
-
Save Sorseg/5623924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
#Grabbing pics from nightmaresfearfactory galleries | |
import re, sys, os | |
import concurrent.futures | |
import urllib.request | |
sfolder = 'pics' | |
os.makedirs(sfolder,exist_ok=True) | |
os.chdir(sfolder) | |
img_re = re.compile('(http://www.nightmaresfearfactory.com/sites/default/files/styles/fear_pic_image/public/(?:.*?/)?(.*?))"') | |
with urllib.request.urlopen(sys.argv[1]) as f: | |
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor: | |
urls = img_re.findall(f.readall().decode('utf8')) | |
executor.left = len(urls) | |
def fetch(url, fname): | |
while os.path.exists(fname): | |
fname = fname +'.' | |
urllib.request.urlretrieve(url, fname) | |
print(executor.left, fname) | |
executor.left -= 1 | |
for url, fname in urls: | |
executor.submit(fetch, url, fname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment