# -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 from datetime import datetime 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() def outofcopyright(): for i in item.models.Item.objects.filter(sort__year__lt=datetime.now().year - 60, level=2): i.level = 1 i.save() def update_double_imdb(): l = itemlist.models.List.get('j:Double IMDb') 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()