diff --git a/backup_edits.py b/backup_edits.py new file mode 100755 index 0000000..438c5b9 --- /dev/null +++ b/backup_edits.py @@ -0,0 +1,39 @@ +#!/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 + path = i['id'].replace(':', '_').replace('/', '_') + '.json' + 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) +