pandora_cms/backup_annotations.py
2018-05-10 14:58:00 +01:00

40 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import json
import os
import sys
import unicodedata
import ox
import ox.api
if __name__ == '__main__':
if len(sys.argv) > 1:
target = sys.argv[1]
else:
target = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Films')
if not target.endswith('/'):
target += '/'
site = 'pandora.cinemusespace.com'
api = ox.api.signin('https://%s/api/' % site)
keep = []
r = api.find({'range': [0, 1000], 'keys': ['id']})
for i in r['data']['items']:
item = api.get(id=i['id'], keys=[])['data']
layers = api.get(id=i['id'], keys=['layers'])['data']
item['layers'] = layers['layers']
director = item.get('director', ['Unknown Director'])
path = os.path.join('; '.join(director), '%s' % (item['title']))
if 'year' in item:
path += ' (%s)' % item['year']
path = ox.decode_html(path)
path = os.path.join(target, path)
ox.makedirs(path)
path = os.path.join(path, 'annotations.json')
with open(path, 'w') as fd:
json.dump(item, fd, ensure_ascii=False, indent=4, sort_keys=True)