Skip to content

Instantly share code, notes, and snippets.

@eviatarbach
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eviatarbach/9193592d1b8611b6a05f to your computer and use it in GitHub Desktop.
Save eviatarbach/9193592d1b8611b6a05f to your computer and use it in GitHub Desktop.
Tretyakov Gallery image download script. You must have ImageMagick installed, and run it in an empty directory since it creates files and will overwrite existing ones if they have the same name. You must call it with the image ID as the argument; for example, for http://www.tretyakovgallery.ru/en/collection/_show/image/_id/331, do python tretyak…
#!/usr/bin/env python
import urllib
import sys
import re
import os
url = 'http://www.tretyakovgallery.ru/ajax/?action=fetch_image&id=%s' % sys.argv[1]
url_finder = re.compile("\['src'\] = '(.+?\.jpg)'")
images = urllib.urlopen(url).read()
image_list = re.findall(url_finder, images)
width = images.count("Images['1']") / 4
height = len(image_list) / width
for index, image in enumerate(image_list):
urllib.urlretrieve('http://www.tretyakovgallery.ru/pictures/' + image, str(index) + '.jpg')
rows = [range(row * width, row * width + width) for row in range(height)]
for index, row in enumerate(rows):
os.system('convert %s +append %s' % (' '.join([str(a) + '.jpg' for a in row]), str(index) + '.png'))
os.system('convert %s -append output.png' % ' '.join(str(a) + '.png' for a in range(len(rows))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment