-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.py
executable file
·56 lines (46 loc) · 1.49 KB
/
convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import deepzoom
import logging
import logging.handlers
import time
# JSON
try:
import json
_parse_json = lambda s: json.loads(s)
except ImportError:
try:
import simplejson
_parse_json = lambda s: simplejson.loads(s)
except ImportError:
# For Google AppEngine
from django.utils import simplejson
_parse_json = lambda s: simplejson.loads(s)
def main():
t = time.time()
# Logging
logger = logging.getLogger('zoomit-flickr-convert-%d'%t)
logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler('zoomit-flickr-convert-%d'%t,
maxBytes=1024*1024, backupCount=100)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
# Conversion
logger.info('Begin %d: ' % t + str(t))
f = open('photos.json')
photos = json.load(f)
images = [photo['dzi'] for photo in photos]
images.reverse() # reverse chronological
collection = deepzoom.DeepZoomCollectionDescriptor('collection-%d.xml' % t)
for image in images:
try:
collection.append(image)
collection.save()
except:
logger.error('Failed: %s'%image)
continue
end = time.time()
logger.info('End %d: ' % t + str(end))
logger.info('Duration %d: ' % t + str(end - t))
if __name__ == '__main__':
main()