oxdata/movieposterdb/cache.py

35 lines
798 B
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
import hashlib
from django.conf import settings
from oxlib.cache import getUrlUnicode
from oxlib import findRe
import oxlib.net
import oxweb.movieposterdb
def getPoster(id, url=''):
if not url:
urls = oxweb.movieposterdb.getPosterUrls(id)
if urls:
url = urls[0]
else:
return
dirname = os.path.join(settings.DATA_ROOT, 'movieposterdb.com', id[:1], id[:4], id)
url_hash = hashlib.sha1(url).hexdigest()
filename = os.path.join(dirname, '%s.jpg' % url_hash)
filename = os.path.normpath(filename)
2009-07-13 10:29:32 +00:00
oxlib.net.saveUrl(url, filename)
2009-07-13 08:09:58 +00:00
return filename
def archivePosters(init=False):
return
def cron():
archivePosters()
def init():
archivePosters(True)