Skip to content

Instantly share code, notes, and snippets.

@Sorseg
Created May 21, 2013 22:54
Show Gist options
  • Save Sorseg/5623924 to your computer and use it in GitHub Desktop.
Save Sorseg/5623924 to your computer and use it in GitHub Desktop.
#!/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