add missing script
This commit is contained in:
parent
e8a78709f7
commit
1a298438e5
1 changed files with 45 additions and 0 deletions
45
add_to_site.py
Normal file
45
add_to_site.py
Normal file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue