njpma/app/video/management/commands/load_titles.py

46 lines
1.8 KiB
Python
Raw Normal View History

2021-09-28 13:10:22 +00:00
from django.core.management.base import BaseCommand
import ox
from ... import models
class Command(BaseCommand):
help = 'import titles from pan.do/ra'
def add_arguments(self, parser):
parser.add_argument("--api", dest="api", type=str, default='https://pad.ma/api/'),
parser.add_argument("--group", dest="group", type=str, default='Asian Art Biennial 2021'),
def handle(self, *args, **options):
api = ox.api.signin(options['api'])
query = {
'query': {
'conditions': [{'key': 'groups', 'value': options['group'], 'operator': '=='}]
},
2021-10-11 14:33:24 +00:00
'keys': [
'id', 'title', 'director', 'summary', 'source', 'sourcedescription', 'date', 'location',
2021-10-13 15:07:12 +00:00
'duration', 'featuring', 'cinematographer',
'hue', 'saturation', 'lightness',
2021-10-11 14:33:24 +00:00
],
2021-09-28 13:10:22 +00:00
'range': [0, 1000]
}
for item in api.find(**query)['data']['items']:
print(item)
f, c = models.Film.objects.get_or_create(padma_id=item['id'])
for key, value in item.items():
2021-10-11 18:03:23 +00:00
if key == 'title':
f.data['title'], f.data['title_zh'] = value.split(' / ', 1)
2021-10-21 13:21:06 +00:00
elif key == 'summary':
f.data['summary'], f.data['summary_zh'] = value.split('<br><br>', 1)
2021-10-11 18:20:13 +00:00
elif key == 'sourcedescription':
if '<br><br>' in value:
f.data['bio'], f.data['bio_zh'] = value.split('<br><br>', 1)
else:
f.data['bio'] = f.data['bio_zh'] = value
2021-10-11 18:03:23 +00:00
elif key != 'id':
2021-10-11 13:44:02 +00:00
f.data[{
}.get(key, key)] = value
2021-10-22 16:36:55 +00:00
if c:
f.public = True
2021-09-28 13:10:22 +00:00
f.slug = item['id']
f.save()