From ebf2ba4dbd354536c348a212b6b9060930202abd Mon Sep 17 00:00:00 2001 From: j Date: Thu, 15 Nov 2018 15:30:49 +0000 Subject: [PATCH 1/2] load annotations in chunks --- ontology/update_keywords.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/ontology/update_keywords.py b/ontology/update_keywords.py index 1b8621e..f829b48 100755 --- a/ontology/update_keywords.py +++ b/ontology/update_keywords.py @@ -9,24 +9,35 @@ site = 'pandora.cinemusespace.com' api = ox.api.signin('https://%s/api/' % site) keywords = collections.Counter() -for annotation in api.findAnnotations({ - 'query': { +query = { 'conditions': [{ 'key': 'layer', 'value': 'keywords', 'operator': '==' }], 'operator': '&' - }, - 'keys': ['id', 'in', 'out', 'value', 'user', 'created'], - 'range': [0, 500000] -})['data']['items']: - if annotation['id'].startswith('BA/'): - continue - keyword = annotation['value'] - if ': ' not in keyword: - keyword = 'other: ' + keyword - keywords[keyword] += 1 +} +count = api.findAnnotations({'query': query})['data']['items'] +position = 0 +chunk = 1000 + +while position < count: + r = api.findAnnotations({ + 'query': query, + 'keys': ['id', 'in', 'out', 'value', 'user', 'created'], + 'sort': [{'key': 'public_id', 'operator': '+'}], + 'range': [position, position+chunk] + }) + if 'data' not in r: + print('failed', r) + for annotation in r['data']['items']: + if annotation['id'].startswith('BA/'): + continue + keyword = annotation['value'] + if ': ' not in keyword: + keyword = 'other: ' + keyword + keywords[keyword] += 1 + position += chunk with open('keywords.json', 'w') as fd: json.dump(keywords, fd, indent=4, ensure_ascii=False, sort_keys=True) From f66de47798b436fddec181687e3c38b210f4acb8 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 15 Nov 2018 15:31:46 +0000 Subject: [PATCH 2/2] update edits every 12 hours --- tasks.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tasks.py b/tasks.py index f1e72c4..d9a6878 100644 --- a/tasks.py +++ b/tasks.py @@ -18,4 +18,11 @@ def subtitles_user(**kwargs): except: pass - +@periodic_task(run_every=timedelta(hours=12), queue='encoding') +def render_edits(**kwargs): + path = '/home/pandora/pandora_render/render_public_edits.py' + if os.path.exists(path) + try: + subprocess.call([path]) + except: + pass