From 079d2b5ad73bc2902d7f3240e93f0fdbbe4d1b7a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 9 Mar 2013 11:42:23 +0000 Subject: [PATCH] add cronjob --- __init__.py | 0 models.py | 3 +++ tasks.py | 28 ++++++++++++++++++++++++++++ views.py | 1 + 4 files changed, 32 insertions(+) create mode 100644 __init__.py create mode 100644 models.py create mode 100644 tasks.py create mode 100644 views.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/models.py b/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/tasks.py b/tasks.py new file mode 100644 index 0000000..79908ae --- /dev/null +++ b/tasks.py @@ -0,0 +1,28 @@ +# -*- 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() + diff --git a/views.py b/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/views.py @@ -0,0 +1 @@ +# Create your views here.