Minimal Imgur front end
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.9 KiB

from gevent import monkey
from gevent import sleep
from threading import Thread
from os import remove, mkdir, path, stat
from shutil import rmtree
from uuid import uuid4
from bottle import route, run
from bottle import static_file
from bottle import SimpleTemplate
from .get import get
from .config import IMAGE_CACHE, template_dir, bind_ip, bind_port
def get_timestamp_of_file(file):
return stat(file).st_ctime
def album(id):
title, metas = get("a/" + id, req)
found_list_file = IMAGE_CACHE + ("a/" + id).replace('/', '_')
with open(found_list_file, 'r') as f:
imgs =',')
for c, img in enumerate(imgs):
imgs[c] = IMAGE_CACHE + imgs[c]
# sort image order (file creation time)
imgs = sorted(imgs, key=get_timestamp_of_file)
for c, img in enumerate(imgs):
imgs[c] = (img.replace(IMAGE_CACHE, '/'), metas[c][0], metas[c][1])
with open(f'{template_dir}gallery.html', 'r') as img_view:
tpl = SimpleTemplate(img_view)
return tpl.render(imgs=imgs, title=title)
def home():
return static_file("index.html", root=template_dir)
def static(file=''):
return static_file(file, root=template_dir)
def gallery(id=''):
return album(id)
def gallery(id=''):
return album(id)
def img(img=''):
if not img.endswith("jpeg") and not img.endswith("jpg") and not img.endswith("png"):
img = img + ".jpg"
img = img.replace('jpeg', 'jpg')
if not path.exists(IMAGE_CACHE + img):
get(img, IMAGE_CACHE)
return static_file(img, root=IMAGE_CACHE)
def start_server():
except FileNotFoundError:
run(server='gevent', host=bind_ip, port=bind_port)