oxdata/lookup/models.py

59 lines
2.2 KiB
Python
Raw Normal View History

2009-07-13 08:09:58 +00:00
# -*- 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
import simplejson
import oxweb.wikipedia
class IdMapping(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
oxdb_id = models.CharField(max_length=42, 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)
wikipedia_url = 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)
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
2009-07-13 08:13:26 +00:00
karagarga_id = models.IntegerField(unique=True, blank=True, null=True, default=None)
2009-07-13 08:09:58 +00:00
def __unicode__(self):
return self.imdb_id
def updateFromWikipedia(self):
if self.wikipedia_url:
data = oxweb.wikipedia.getMovieData(self.wikipedia_url)
_key = {}
for key in ('imdb_id',
'amg_id',
'rottentomatoes_id'):
if key in data:
if data[key]:
setattr(self, _key.get(key, key), data[key])
self.save()
def json(self):
json = {}
for key in ('imdb_id',
'amg_id',
'oxdb_id',
'wikipedia_url',
'movieposterdb_id',
'impawards_url',
'rottentomatoes_id'):
value = getattr(self, key)
if value:
json[key] = value
return simplejson.dumps(json, indent=4)