# -*- 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: data = oxweb.impawards.getData(id) if 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 criterionId in oxweb.criterion.getIds(): if models.MovieId.objects.all().filter(criterion_id=id).count() == 0: data = oxweb.criterion.getData(criterionId) if 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) #kg lastId = models.Karagarga.maxId() for karagargaId in oxweb.karagarga.getIds(lastId): if models.Karagarga.objects.filter(karagarga_id=karagargaId).count() == 0: data = oxweb.karagarga.getData(karagargaId) if data: if 'imdbId' in data: m = models.getMovieIdByImdbId(data['imdbId']) kg = models.Karagarga() kg.movie_id = m kg.karagarga_id = karagargaId kg.save() #fixme, what to do else? for poster in data['posters']: addPoster(poster, 'karagarga.net', kg.karagarga_id)