39 lines
931 B
Python
39 lines
931 B
Python
# -*- 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 getPosterFilename(id, url):
|
|
id = str(id)
|
|
dirname = os.path.join(settings.DATA_ROOT, 'karagarga.net', id[:1], id)
|
|
url_hash = hashlib.sha1(url).hexdigest()
|
|
filename = os.path.join(dirname, '%s.jpg' % url_hash)
|
|
filename = os.path.normpath(filename)
|
|
return filename
|
|
|
|
def getPoster(id, url):
|
|
filename = getPosterFilename(id, url)
|
|
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)
|
|
|