getMappingByImdb
This commit is contained in:
parent
578b133b55
commit
67e9071c3f
2 changed files with 16 additions and 8 deletions
|
@ -8,7 +8,7 @@ from oxlib import findRe
|
||||||
import oxlib.net
|
import oxlib.net
|
||||||
import oxweb.criterion
|
import oxweb.criterion
|
||||||
|
|
||||||
from oxdata.lookup.models import IdMapping
|
from oxdata.lookup.models import IdMapping, getMappingByImdb
|
||||||
|
|
||||||
|
|
||||||
def getPoster(id, url=None):
|
def getPoster(id, url=None):
|
||||||
|
@ -29,17 +29,16 @@ def getPoster(id, url=None):
|
||||||
|
|
||||||
def archivePosters(init=False):
|
def archivePosters(init=False):
|
||||||
for criterionId in oxweb.criterion.getIds():
|
for criterionId in oxweb.criterion.getIds():
|
||||||
|
data = oxweb.criterion.getData(criterionId)
|
||||||
|
imdbId = data['imdbId']
|
||||||
try:
|
try:
|
||||||
m = IdMapping.objects.get(criterion_id=criterionId)
|
m = IdMapping.objects.get(criterion_id=criterionId)
|
||||||
|
if imdbId and imdb != m.imdb_id:
|
||||||
|
m.imdb_id = imdbId
|
||||||
|
m.save()
|
||||||
except IdMapping.DoesNotExist:
|
except IdMapping.DoesNotExist:
|
||||||
data = oxweb.criterion.getData(criterionId)
|
|
||||||
imdbId = data['imdbId']
|
|
||||||
if imdbId:
|
if imdbId:
|
||||||
try:
|
m = getMappingByImdb(imdbId)
|
||||||
m = IdMapping.objects.get(imdb_id=imdbId)
|
|
||||||
except IdMapping.DoesNotExist:
|
|
||||||
m = IdMapping()
|
|
||||||
m.imdb_id = imdbId
|
|
||||||
else:
|
else:
|
||||||
m = IdMapping()
|
m = IdMapping()
|
||||||
m.criterion_id = criterionId
|
m.criterion_id = criterionId
|
||||||
|
|
|
@ -9,6 +9,15 @@ import simplejson
|
||||||
import oxweb.wikipedia
|
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):
|
class IdMapping(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
modified = models.DateTimeField(auto_now=True)
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
|
Loading…
Reference in a new issue