pandora_indiancinema/tasks.py

35 lines
1 KiB
Python
Raw Normal View History

2013-03-09 11:42:23 +00:00
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from datetime import datetime
2013-03-09 11:42:23 +00:00
from celery.task import periodic_task
from celery.schedules import crontab
from django.db import transaction
import itemlist.models
import item.models
@periodic_task(run_every=crontab(hour=6, minute=0), queue='encoding')
def cron(**kwargs):
update_double_imdb()
outofcopyright()
2013-03-09 11:42:23 +00:00
def outofcopyright():
for i in item.models.Item.objects.filter(sort__year__lt=datetime.now().year - 60, level=2):
i.level = 1
i.save()
2013-03-09 11:42:23 +00:00
def update_double_imdb():
2014-02-14 08:06:07 +00:00
l = itemlist.models.List.get('j:Double IMDb')
2013-03-09 11:42:23 +00:00
for i in item.models.Item.objects.filter(data__contains='imdbId').exclude(id__in=l.items.all()):
if item.models.Item.objects.exclude(id=i.id).filter(sort__imdbId=i.sort.imdbId).exists():
l.add(i)
for i in l.items.all():
if not i.get('imdbId') or \
item.models.Item.objects.filter(sort__imdbId=i.sort.imdbId).count() == 1:
l.remove(i)
transaction.commit_unless_managed()