oxdata/lookup/cache.py
2009-08-20 19:03:14 +02:00

62 lines
2.2 KiB
Python

# -*- coding: UTF-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import os
from django.conf import settings
from oxlib.cache import getUrlUnicode
from oxlib import findRe
import oxlib.net
import oxweb.criterion
import oxweb.karagarga
import oxweb.imdb
import oxweb.impawards
import models
from oxdata.poster.models import PosterCache
def addPoster(m, url, site, site_id):
if PosterCache.objects.all().filter(url=url).count() == 0:
p = PosterCache(url=url, site=site, site_id=site_id, movie_id=m)
p.save()
def getIds():
for id in oxweb.impawards.getIds():
if models.MovieId.objects.all().filter(impawards_id=id).count() == 0:
print 'impawards', id
data = oxweb.impawards.getData(id)
if data and 'imdbId' in data:
m = models.getMovieIdByImdbId(data['imdbId'])
if not m.impawards_id:
m.impawards_id = id
m.save()
for poster in data['posters']:
addPoster(m, poster, 'impawards.com', m.imdb_id)
for id in oxweb.criterion.getIds():
if models.MovieId.objects.all().filter(criterion_id=id).count() == 0:
print 'criterion', id
data = oxweb.criterion.getData(id)
if data and 'imdbId' in data:
m = models.getMovieIdByImdbId(data['imdbId'])
if not m.criterion_id:
m.criterion_id = id
m.save()
addPoster(m, poster, 'criterion.com', m.criterion_id)
else:
print data['title'], "no imdbId"
#kg
lastId = models.Karagarga.maxId()
for id in oxweb.karagarga.getIds(lastId):
if models.Karagarga.objects.filter(karagarga_id=id).count() == 0:
print 'kg', id
data = oxweb.karagarga.getData(id)
if data and 'imdbId' in data:
m = models.getMovieIdByImdbId(data['imdbId'])
kg = models.Karagarga()
kg.movie_id = m
kg.karagarga_id = id
kg.save()
for poster in data['posters']:
addPoster(m, poster, 'karagarga.net', kg.karagarga_id)