load host settings, fix oxid for series, load data from imdb

This commit is contained in:
j 2009-07-14 12:51:49 +02:00
parent 840c2f6b72
commit 99e498b077
2 changed files with 31 additions and 8 deletions

View file

@ -9,6 +9,8 @@ from django.contrib.auth.models import User
import simplejson import simplejson
import oxweb.wikipedia import oxweb.wikipedia
import oxweb.imdb
from oxlib import stripTags
def getMovieIdByImdbId(imdb_id): def getMovieIdByImdbId(imdb_id):
@ -47,7 +49,8 @@ class MovieId(models.Model):
def __unicode__(self): def __unicode__(self):
id = self.imdb_id id = self.imdb_id
if id: id = self.id if not id:
id = self.id
return '%s (%s)' % (self.title, id) return '%s (%s)' % (self.title, id)
def updateFromWikipedia(self): def updateFromWikipedia(self):
@ -63,11 +66,25 @@ class MovieId(models.Model):
setattr(self, _key.get(key, key), data[key]) setattr(self, _key.get(key, key), data[key])
self.save() self.save()
def updateFromImdb(self):
if self.imdb_id:
data = oxweb.imdb.getMovieInfo(self.imdb_id)
_key = {
'episode title': 'episode_title',
'series title': 'series_title',
}
for key in ('title', 'year', 'series title', 'episode title', 'season', 'episode'):
if key in data and data[key]:
setattr(self, _key.get(key, key), data[key])
directors = oxweb.imdb.getMovieCredits(self.imdb_id)['directors']
self.director = ', '.join([stripTags(d[0]) for d in directors])
self.save()
def gen_oxdb_id(self): def gen_oxdb_id(self):
oxid_value = u"\n".join([self.title, self.director, self.year]) oxid_value = u"\n".join([self.title, self.director, self.year])
oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest() oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()
if self.episode > -1: if self.episode > -1:
oxid_value = u"\n".join([self.title, "%02d" % self.season]) oxid_value = u"\n".join([self.series_title, "%02d" % self.season])
oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20] oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20]
oxid_value = u"\n".join(["%02d" % self.episode, self.episode_title, self.director, self.year]) oxid_value = u"\n".join(["%02d" % self.episode, self.episode_title, self.director, self.year])
oxid += hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20] oxid += hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20]
@ -87,11 +104,7 @@ class MovieId(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): class Karagarga(models.Model):
mapping = models.ForeignKey(MovieId, related_name='karagarga_ids', default=None) movie_id = models.ForeignKey(MovieId, related_name='karagarga_ids', default=None)
karagarga_id = models.IntegerField(unique=True) karagarga_id = models.IntegerField(unique=True)

View file

@ -6,7 +6,7 @@ from os.path import join
PROJECT_PATH = os.path.dirname(__file__) PROJECT_PATH = os.path.dirname(__file__)
DEBUG = True DEBUG = False
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
ADMINS = ( ADMINS = (
@ -97,3 +97,13 @@ INSTALLED_APPS = (
LOGIN_REDIRECT_URL='/' LOGIN_REDIRECT_URL='/'
try:
import socket
# hostname = socket.gethostname().replace('.','_')
# exec "from host_settings.%s import *" % hostname
local_settings_module = socket.gethostname().split(".")[0]
if local_settings_module:
execfile(os.path.join(PROJECT_PATH, "host_settings", "%s.py" % local_settings_module))
except ImportError, e:
raise e