Skip to content

Instantly share code, notes, and snippets.

@robinkraft
Created August 5, 2014 17:14
Show Gist options
  • Save robinkraft/44706039d4c69473898b to your computer and use it in GitHub Desktop.
Save robinkraft/44706039d4c69473898b to your computer and use it in GitHub Desktop.
precache images for crowdsourcing app
import sys
import requests
import multiprocessing
URL = 'http://forma-cs-validation.elasticbeanstalk.com/api/alerts/next/cache'
def f(a):
try:
r = requests.get(URL)
print r
try:
x = r.json()['message']
if 'Error: No uncached alerts' in x:
sys.exit()
except KeyError:
return r
except requests.exceptions.ConnectionError:
print "Connection error"
return None
if __name__ == '__main__':
cpus = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=cpus)
pool.map(f, range(1000000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment