rename
This commit is contained in:
parent
183c7fb497
commit
dd5ebf0ed5
10 changed files with 99 additions and 30 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, getMappingByImdb
|
from oxdata.lookup.models import MovieId, getMovieIdByImdbId
|
||||||
|
|
||||||
|
|
||||||
def getPoster(id, url=None):
|
def getPoster(id, url=None):
|
||||||
|
@ -27,15 +27,15 @@ def archivePosters(init=False):
|
||||||
data = oxweb.criterion.getData(criterionId)
|
data = oxweb.criterion.getData(criterionId)
|
||||||
imdbId = data['imdbId']
|
imdbId = data['imdbId']
|
||||||
try:
|
try:
|
||||||
m = IdMapping.objects.get(criterion_id=criterionId)
|
m = MovieId.objects.get(criterion_id=criterionId)
|
||||||
if imdbId and imdbId != m.imdb_id:
|
if imdbId and not m.imdb_id:
|
||||||
m.imdb_id = imdbId
|
m.imdb_id = imdbId
|
||||||
m.save()
|
m.save()
|
||||||
except IdMapping.DoesNotExist:
|
except MovieId.DoesNotExist:
|
||||||
if imdbId:
|
if imdbId:
|
||||||
m = getMappingByImdb(imdbId)
|
m = getMovieIdByImdbId(imdbId)
|
||||||
else:
|
else:
|
||||||
m = IdMapping()
|
m = MovieId()
|
||||||
m.criterion_id = criterionId
|
m.criterion_id = criterionId
|
||||||
m.save()
|
m.save()
|
||||||
url = data['posterUrl']
|
url = data['posterUrl']
|
||||||
|
|
|
@ -9,16 +9,16 @@ import simplejson
|
||||||
import oxweb.wikipedia
|
import oxweb.wikipedia
|
||||||
|
|
||||||
|
|
||||||
def getMappingByImdb(imdb_id):
|
def getMovieIdByImdbId(imdb_id):
|
||||||
try:
|
try:
|
||||||
m = IdMapping.objects.get(imdb_id=imdb_id)
|
m = MovieId.objects.get(imdb_id=imdb_id)
|
||||||
except IdMapping.DoesNotExist:
|
except MovieId.DoesNotExist:
|
||||||
m = IdMapping()
|
m = MovieId()
|
||||||
m.imdb_id = imdb_id
|
m.imdb_id = imdb_id
|
||||||
m.save()
|
m.save()
|
||||||
return m
|
return m
|
||||||
|
|
||||||
class IdMapping(models.Model):
|
class MovieId(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)
|
||||||
|
|
||||||
|
@ -26,22 +26,23 @@ class IdMapping(models.Model):
|
||||||
imdb_id = models.CharField(max_length=7, unique=True, blank=True, null=True, default=None)
|
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)
|
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)
|
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_id = 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)
|
|
||||||
rottentomatoes_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
|
#FIXME: look into other ids
|
||||||
#what about tv.com ids/urls for tv episodes
|
#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):
|
def __unicode__(self):
|
||||||
return self.imdb_id
|
return self.imdb_id
|
||||||
|
|
||||||
def updateFromWikipedia(self):
|
def updateFromWikipedia(self):
|
||||||
if self.wikipedia_url:
|
if self.wikipedia_id:
|
||||||
data = oxweb.wikipedia.getMovieData(self.wikipedia_url)
|
wikipedia_url = "http://en.wikipedia.org/wiki/%s" % self.wikipedia_id
|
||||||
|
data = oxweb.wikipedia.getMovieData(wikipedia_url)
|
||||||
_key = {}
|
_key = {}
|
||||||
for key in ('imdb_id',
|
for key in ('imdb_id',
|
||||||
'amg_id',
|
'amg_id',
|
||||||
|
@ -57,7 +58,6 @@ class IdMapping(models.Model):
|
||||||
'amg_id',
|
'amg_id',
|
||||||
'oxdb_id',
|
'oxdb_id',
|
||||||
'wikipedia_url',
|
'wikipedia_url',
|
||||||
'movieposterdb_id',
|
|
||||||
'impawards_url',
|
'impawards_url',
|
||||||
'rottentomatoes_id'):
|
'rottentomatoes_id'):
|
||||||
value = getattr(self, key)
|
value = getattr(self, key)
|
||||||
|
@ -65,3 +65,11 @@ class IdMapping(models.Model):
|
||||||
json[key] = value
|
json[key] = value
|
||||||
return simplejson.dumps(json, indent=4)
|
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
7
lookup/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
urlpatterns = patterns('oxdata.lookup.views',
|
||||||
|
(r'^$', 'ids'),
|
||||||
|
(r'^urls$', 'urls'),
|
||||||
|
)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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 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
6
poster/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
urlpatterns = patterns('oxdata.poster.views',
|
||||||
|
(r'^$', 'poster'),
|
||||||
|
)
|
||||||
|
|
|
@ -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
16
urls.py
|
@ -1,17 +1,15 @@
|
||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
# Uncomment the next two lines to enable the admin:
|
# Uncomment the next two lines to enable the admin:
|
||||||
# from django.contrib import admin
|
from django.contrib import admin
|
||||||
# admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
# Example:
|
(r'^poster/', include('oxdata.poster.urls')),
|
||||||
# (r'^oxdata/', include('oxdata.foo.urls')),
|
(r'^id/', include('oxdata.lookup.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')),
|
|
||||||
|
|
||||||
# Uncomment the next line to enable the admin:
|
# Uncomment the next line to enable the admin:
|
||||||
# (r'^admin/(.*)', admin.site.root),
|
(r'^admin/(.*)', admin.site.root),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
9
utils/shortcuts.py
Normal file
9
utils/shortcuts.py
Normal 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)
|
||||||
|
|
Loading…
Reference in a new issue