pandora_cms/backup_edits.py

40 lines
985 B
Python
Raw Normal View History

2018-11-15 11:00:33 +00:00
#!/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__)), 'Edits')
if not target.endswith('/'):
target += '/'
site = 'pandora.cinemusespace.com'
api = ox.api.signin('https://%s/api/' % site)
keep = []
r = api.findEdits({
'range': [0, 1000],
'keys': ['id']
})
for i in r['data']['items']:
edit = api.getEdit(id=i['id'])['data']
if edit['status'] == 'private':
continue
2018-12-11 14:37:47 +00:00
path = i['id'].replace(':', '_').replace('/', '_').replace('|', '_') + '.json'
2018-11-15 11:00:33 +00:00
path = ox.decode_html(path)
path = os.path.join(target, path)
ox.makedirs(os.path.dirname(path))
with open(path, 'w') as fd:
json.dump(edit, fd, ensure_ascii=False, indent=4, sort_keys=True)