Skip to content

Instantly share code, notes, and snippets.

@atarkowska
Last active November 17, 2016 11:38
Show Gist options
  • Save atarkowska/23a59883416ff7cc0d1a79e8e9db2a38 to your computer and use it in GitHub Desktop.
Save atarkowska/23a59883416ff7cc0d1a79e8e9db2a38 to your computer and use it in GitHub Desktop.
populate thumbnails
import requests
COOKIE_NAME = "sessionid_demo3c"
HOST = "http://idr-clone.openmicroscopy.org"
INDEX_PAGE = "{host}/webclient".format(**{'host': HOST})
THUMBNAIL_URL = "{host}/webgateway/render_thumbnail/{image_id}/"
MAP_IMAGE_URL = "{host}/webclient/api/annotations/?type=map&image={image_id}"
def prepare_url(url, params={}):
params['host'] = HOST
u = url.format(**params)
return u
def send_get_request(session, url, cookies):
r = session.get(url, cookies=cookies)
print r.url, r.status_code
if r.status_code != 200:
r.raise_for_status()
return r
def send_post_request(session, url, cookies):
r = session.post(url, cookies=cookies)
print r.url, r.status_code
if r.status_code != 200:
r.raise_for_status()
return r
if __name__ == '__main__':
with requests.Session() as session:
req = requests.Request('GET', INDEX_PAGE)
prepped = session.prepare_request(req)
res = session.send(prepped)
cookies = dict(sessionid=res.cookies[COOKIE_NAME])
for x in xrange(1461, 3125675):
_url = prepare_url(THUMBNAIL_URL, {'image_id':x})
send_get_request(session, _url, cookies)
_url = prepare_url(MAP_IMAGE_URL, {'image_id':x})
send_get_request(session, _url, cookies)
#send_post_request(session, LOGOUT_PAGE, cookies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment