This commit is contained in:
j 2009-07-13 14:32:01 +02:00
parent 183c7fb497
commit dd5ebf0ed5
10 changed files with 99 additions and 30 deletions

View file

@ -8,7 +8,7 @@ from oxlib import findRe
import oxlib.net
import oxweb.criterion
from oxdata.lookup.models import IdMapping, getMappingByImdb
from oxdata.lookup.models import MovieId, getMovieIdByImdbId
def getPoster(id, url=None):
@ -27,15 +27,15 @@ def archivePosters(init=False):
data = oxweb.criterion.getData(criterionId)
imdbId = data['imdbId']
try:
m = IdMapping.objects.get(criterion_id=criterionId)
if imdbId and imdbId != m.imdb_id:
m = MovieId.objects.get(criterion_id=criterionId)
if imdbId and not m.imdb_id:
m.imdb_id = imdbId
m.save()
except IdMapping.DoesNotExist:
except MovieId.DoesNotExist:
if imdbId:
m = getMappingByImdb(imdbId)
m = getMovieIdByImdbId(imdbId)
else:
m = IdMapping()
m = MovieId()
m.criterion_id = criterionId
m.save()
url = data['posterUrl']

View file

@ -9,16 +9,16 @@ import simplejson
import oxweb.wikipedia
def getMappingByImdb(imdb_id):
def getMovieIdByImdbId(imdb_id):
try:
m = IdMapping.objects.get(imdb_id=imdb_id)
except IdMapping.DoesNotExist:
m = IdMapping()
m = MovieId.objects.get(imdb_id=imdb_id)
except MovieId.DoesNotExist:
m = MovieId()
m.imdb_id = imdb_id
m.save()
return m
class IdMapping(models.Model):
class MovieId(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
@ -26,22 +26,23 @@ class IdMapping(models.Model):
imdb_id = models.CharField(max_length=7, unique=True, blank=True, null=True, default=None)
amg_id = models.IntegerField(unique=True, blank=True, null=True, default=None)
wikipedia_url = models.CharField(unique=True, max_length=255, blank=True, null=True, default=None)
wikipedia_id = models.CharField(unique=True, max_length=255, blank=True, null=True, default=None)
criterion_id = models.IntegerField(unique=True, blank=True, null=True, default=None)
movieposterdb_url = models.CharField(max_length=255, unique=True, blank=True, null=True, default=None)
impawards_url = models.CharField(max_length=255, unique=True, blank=True, null=True, default=None)
impawards_id = models.CharField(max_length=255, unique=True, blank=True, null=True, default=None)
rottentomatoes_id = models.CharField(max_length=255, unique=True, blank=True, null=True, default=None)
#FIXME: look into other ids
#what about tv.com ids/urls for tv episodes
karagarga_id = models.IntegerField(unique=True, blank=True, null=True, default=None)
#movieposterdb can be mapped via imdbid and does not need to be saved here
def __unicode__(self):
return self.imdb_id
def updateFromWikipedia(self):
if self.wikipedia_url:
data = oxweb.wikipedia.getMovieData(self.wikipedia_url)
if self.wikipedia_id:
wikipedia_url = "http://en.wikipedia.org/wiki/%s" % self.wikipedia_id
data = oxweb.wikipedia.getMovieData(wikipedia_url)
_key = {}
for key in ('imdb_id',
'amg_id',
@ -57,7 +58,6 @@ class IdMapping(models.Model):
'amg_id',
'oxdb_id',
'wikipedia_url',
'movieposterdb_id',
'impawards_url',
'rottentomatoes_id'):
value = getattr(self, key)
@ -65,3 +65,11 @@ class IdMapping(models.Model):
json[key] = value
return simplejson.dumps(json, indent=4)
def getMappingByKaragargaId(id):
kg = Karagarga.objects.get(imdb_id=imdb_id)
return kg.mapping
class Karagarga(models.Model):
mapping = models.ForeignKey(MovieId, related_name='karagarga_ids', default=None)
karagarga_id = models.IntegerField(unique=True)

7
lookup/urls.py Normal file
View file

@ -0,0 +1,7 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('oxdata.lookup.views',
(r'^$', 'ids'),
(r'^urls$', 'urls'),
)

View file

@ -1 +1,17 @@
# Create your views here.
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import os.path
from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User
from oxdata.utils.shortcuts import render_to_json_response
def ids(request):
json = {}
return render_to_json_response(json)
def urls(request):
json = {}
return render_to_json_response(json)

View file

@ -1,3 +1,16 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import os.path
from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User
from oxdata.lookup.models import MovieId
class Poster(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
movie_id = models.ForeignKey(MovieId, related_name='poster')
url = models.CharField(max_length=255)
# Create your models here.

6
poster/urls.py Normal file
View file

@ -0,0 +1,6 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('oxdata.poster.views',
(r'^$', 'poster'),
)

View file

@ -1 +1,13 @@
# Create your views here.
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import os.path
from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User
from oxdata.utils.shortcuts import render_to_json_response
def poster(request):
#FIXME: get MovieId from provided id and redirect to poster url

16
urls.py
View file

@ -1,17 +1,15 @@
from django.conf.urls.defaults import *
from django.conf import settings
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^oxdata/', include('oxdata.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^poster/', include('oxdata.poster.urls')),
(r'^id/', include('oxdata.lookup.urls')),
# Uncomment the next line to enable the admin:
# (r'^admin/(.*)', admin.site.root),
(r'^admin/(.*)', admin.site.root),
)

0
utils/__init__.py Normal file
View file

9
utils/shortcuts.py Normal file
View file

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from django.http import HttpResponse
from django.utils import simplejson
def render_to_json_response(dictionary, content_type="text/json"):
return HttpResponse(simplejson.dumps(dictionary), content_type=content_type)