# -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 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() def update_double_imdb(): l = itemlist.models.List.get(name='Double IMDb', user__username='j') 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()