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

49 lines
2 KiB
Python

from django.core.management.base import BaseCommand
from django.conf import settings
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=settings.DEFAULT_PANDORA_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': '=='}]
},
'keys': [
'id', 'title', 'director', 'summary', 'source', 'sourcedescription', 'date', 'location',
'duration', 'featuring', 'cinematographer',
'hue', 'saturation', 'lightness',
],
'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():
if key == 'title':
if ' / ' in value:
f.data['title'], f.data['title_zh'] = value.split(' / ', 1)
else:
f.data['title'] = value
f.data['title_zh'] = ''
elif key == 'summary':
f.data['summary'], f.data['summary_zh'] = value.split('<br><br>', 1)
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
elif key != 'id':
f.data[{
}.get(key, key)] = value
if c:
f.public = True
f.slug = item['id']
f.save()