update j:Keywords once per day
This commit is contained in:
parent
d99300e5a9
commit
0c9271895f
1 changed files with 18 additions and 0 deletions
18
tasks.py
18
tasks.py
|
@ -1,18 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from datetime import datetime
|
||||
from collections import Counter
|
||||
|
||||
import ox
|
||||
from celery.task import periodic_task
|
||||
from celery.schedules import crontab
|
||||
from django.db import transaction
|
||||
|
||||
import itemlist.models
|
||||
import item.models
|
||||
import annotation.models
|
||||
import text.models
|
||||
|
||||
@periodic_task(run_every=crontab(hour=6, minute=0), queue='encoding')
|
||||
def cron(**kwargs):
|
||||
update_double_imdb()
|
||||
outofcopyright()
|
||||
update_keywords()
|
||||
|
||||
def outofcopyright():
|
||||
for i in item.models.Item.objects.filter(sort__year__lt=datetime.now().year - 60, level=2):
|
||||
|
@ -32,3 +37,16 @@ def update_double_imdb():
|
|||
|
||||
transaction.commit_unless_managed()
|
||||
|
||||
|
||||
def update_keywords():
|
||||
t = text.models.Text.get('j:Keywords')
|
||||
keywords = Counter([a['value']
|
||||
for a in annotation.models.Annotation.objects.filter(layer='keywords').all().values('value')
|
||||
])
|
||||
data = ['<ul>']
|
||||
for k in sorted(keywords.keys(), key=lambda k: ox.sort_string('%s %s' % (keywords[k], k)), reverse=True):
|
||||
data.append('<li>%d <a href="/clip/keywords==%s">%s</a>' %((keywords[k], k.replace(' ', '_'), k)))
|
||||
data.append('</ul>')
|
||||
t.text = '\n'.join(data)
|
||||
t.save()
|
||||
|
||||
|
|
Loading…
Reference in a new issue