diff --git a/add_to_site.py b/add_to_site.py new file mode 100644 index 0000000..ee82e63 --- /dev/null +++ b/add_to_site.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +from optparse import OptionParser +import json +import codecs +import sys +import os +from datetime import datetime + +import ox + +def add_to_site(site, films): + api = ox.api.signin(site) + + for film in sorted(films, key=lambda film: (film['year'], film['title'])): + if len(film['country']) > 2 or film['country'][0] != 'India': + print(film['imdbId'], film['country']) + continue + r = api.find({ + 'query': {'conditions': [{'key': 'imdbId', 'value': film['imdbId']}]}, + 'keys': ['id'], + })['data']['items'] + if not r: + if 'type' in film: + del film['type'] + r = api.add(film)['data'] + item_id = r['id'] + api.addListItems({ + 'items': [item_id], + 'list': 'j:Added Automatically' + }) + print(film['year'], film['imdbId'], r['id']) + return + + +if __name__ == '__main__': + usage = "usage: %prog [options] sitename.org films_with_metadata.json" + parser = OptionParser(usage=usage) + (opts, args) = parser.parse_args() + if len(args) != 2: + parser.print_help() + sys.exit(1) + site, filename = args + with open(filename) as fd: + films = json.load(fd) + add_to_site(site, films)