getMappingByImdb

This commit is contained in:
j 2009-07-13 10:29:42 +02:00
parent 578b133b55
commit 67e9071c3f
2 changed files with 16 additions and 8 deletions

View file

@ -8,7 +8,7 @@ from oxlib import findRe
import oxlib.net
import oxweb.criterion
from oxdata.lookup.models import IdMapping
from oxdata.lookup.models import IdMapping, getMappingByImdb
def getPoster(id, url=None):
@ -29,17 +29,16 @@ def getPoster(id, url=None):
def archivePosters(init=False):
for criterionId in oxweb.criterion.getIds():
data = oxweb.criterion.getData(criterionId)
imdbId = data['imdbId']
try:
m = IdMapping.objects.get(criterion_id=criterionId)
if imdbId and imdb != m.imdb_id:
m.imdb_id = imdbId
m.save()
except IdMapping.DoesNotExist:
data = oxweb.criterion.getData(criterionId)
imdbId = data['imdbId']
if imdbId:
try:
m = IdMapping.objects.get(imdb_id=imdbId)
except IdMapping.DoesNotExist:
m = IdMapping()
m.imdb_id = imdbId
m = getMappingByImdb(imdbId)
else:
m = IdMapping()
m.criterion_id = criterionId

View file

@ -9,6 +9,15 @@ import simplejson
import oxweb.wikipedia
def getMappingByImdb(imdb_id):
try:
m = IdMapping.objects.get(imdb_id=imdb_id)
except IdMapping.DoesNotExist:
m = IdMapping()
m.imdb_id = imdb_id
m.save()
return m
class IdMapping(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)