add patch dict to overwrite imdb data

This commit is contained in:
j 2012-09-25 13:54:13 +02:00
parent 4c4164012b
commit acfd3e1fbc
4 changed files with 43 additions and 0 deletions

View file

View file

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import json
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from ...models import Imdb
class Command(BaseCommand):
"""
load new ids into cache
"""
help = 'load ids from sites that dont support search.'
args = '<json patches>'
def handle(self, *args, **options):
for arg in args:
with open(arg) as f:
data = json.load(f)
for id in data:
i, created = Imdb.objects.get_or_create(imdb=id)
i.patch = data[id]
i.update()
i.save()
print i

View file

@ -9,6 +9,7 @@ from urllib import quote
from django.db import models
from django.conf import settings
import ox
from ox.django.fields import DictField
from lookup.models import get_movie_id
from poster.models import getPosters
@ -72,6 +73,7 @@ class Imdb(models.Model):
seriesTitle = models.CharField(max_length=1000, blank=True, default='')
invalid = models.BooleanField(default=False)
patch = DictField(default=None, blank=True)
def __unicode__(self):
return u"[%s] %s%s" % (self.imdb, self.title, self.year and ' (%s)' % self.year or '')
@ -79,8 +81,21 @@ class Imdb(models.Model):
keys = ('title', 'director', 'year', 'season', 'episode',
'seriesTitle', 'episodeTitle', 'episodeYear', 'episodeDirector')
def apply_patch(self, data):
if self.patch:
data.update(self.patch)
if 'seriesTitle' in data and 'episodeTitle' in data:
if 'season' in data and 'episode' in data:
data['title'] = "%s (S%02dE%02d) %s" % (
data['seriesTitle'], data['season'], data['episode'], data['episodeTitle'])
else:
data['title'] = "%s (S01) %s" % (data['seriesTitle'], data['episodeTitle'])
data['title'] = data['title'].strip()
return data
def update(self):
info = ox.web.imdb.ImdbCombined(self.imdb)
info = self.apply_patch(info)
if info:
for key in self.keys:
if key in info:
@ -101,6 +116,7 @@ class Imdb(models.Model):
def data(self, request=None, timeout=ox.cache.cache_timeout):
data = ox.web.imdb.Imdb(self.imdb, timeout=timeout)
data = self.apply_patch(data)
def fix_links(t):
def fix_names(m):
return '<a href="/name=%s">%s</a>' % (