add some cache data
This commit is contained in:
parent
86ab85024d
commit
294dbc8bac
11 changed files with 279 additions and 9 deletions
40
movieposterdb/cache.py
Normal file
40
movieposterdb/cache.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# -*- 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)
|
||||
if not os.path.exists(filename):
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
data = oxlib.net.getUrl(url)
|
||||
f = open(filename, 'w')
|
||||
f.write(data)
|
||||
f.close()
|
||||
return filename
|
||||
|
||||
def archivePosters(init=False):
|
||||
return
|
||||
|
||||
def cron():
|
||||
archivePosters()
|
||||
|
||||
def init():
|
||||
archivePosters(True)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue