mirror of
https://github.com/apachecn/epub-crawler.git
synced 2025-06-07 18:11:12 +00:00
2022-03-15 23:07:21
This commit is contained in:
parent
6ae1f61fda
commit
898622e928
@ -9,6 +9,11 @@ import tempfile
|
||||
import sys
|
||||
from os import path
|
||||
import uuid
|
||||
import tempfile
|
||||
import json
|
||||
|
||||
bundle_dir = tempfile.gettempdir()
|
||||
cache_dir = 'epubcralwer'
|
||||
|
||||
is_pic = lambda x: x.endswith('.jpg') or \
|
||||
x.endswith('.jpeg') or \
|
||||
@ -68,4 +73,32 @@ def load_module(fname):
|
||||
shutil.copy(fname, nfname)
|
||||
mod = __import__(mod_name)
|
||||
safe_remove(nfname)
|
||||
return mod
|
||||
return mod
|
||||
|
||||
def load_article(hash):
|
||||
fname = path.join(bundle_dir, cache_dir, f'{hash}.json')
|
||||
if not path.isfile(fname):
|
||||
return None
|
||||
try:
|
||||
return json.loads(open(fname, encoding='utf8').read())
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
return None
|
||||
|
||||
def save_article(hash, art):
|
||||
dir = path.join(bundle_dir, cache_dir)
|
||||
safe_mkdir(dir)
|
||||
fname = path.join(dir, f'{hash}.json')
|
||||
open(fname, 'w', encoding='utf-8').write(json.dumps(art))
|
||||
|
||||
def load_img(hash, opti):
|
||||
fname = path.join(bundle_dir, cache_dir, f'{hash}-{opti}.png')
|
||||
if not path.isfile(fname):
|
||||
return None
|
||||
return open(fname, 'rb').read()
|
||||
|
||||
def save_img(hash, opti, img):
|
||||
dir = path.join(bundle_dir, cache_dir)
|
||||
safe_mkdir(dir)
|
||||
fname = path.join(dir, f'{hash}-{opti}.png')
|
||||
open(fname, 'wb').write(img)
|
Loading…
x
Reference in New Issue
Block a user