2022-01-19 10:07:11 +00:00
|
|
|
from files.__main__ import app
|
|
|
|
from .get import *
|
|
|
|
from os import listdir, environ
|
|
|
|
from .const import *
|
2022-04-06 22:54:09 +00:00
|
|
|
import time
|
2022-05-08 05:14:24 +00:00
|
|
|
from datetime import datetime
|
2022-01-19 10:07:11 +00:00
|
|
|
|
|
|
|
@app.template_filter("post_embed")
|
|
|
|
def post_embed(id, v):
|
|
|
|
|
|
|
|
try: id = int(id)
|
|
|
|
except: return None
|
|
|
|
|
|
|
|
p = get_post(id, v, graceful=True)
|
|
|
|
|
2022-01-28 19:27:16 +00:00
|
|
|
if p: return render_template("submission_listing.html", listing=[p], v=v)
|
|
|
|
return ''
|
2022-01-19 10:07:11 +00:00
|
|
|
|
2022-04-06 22:54:09 +00:00
|
|
|
|
|
|
|
@app.template_filter("timestamp")
|
|
|
|
def timestamp(timestamp):
|
|
|
|
|
|
|
|
age = int(time.time()) - timestamp
|
|
|
|
|
|
|
|
if age < 60:
|
|
|
|
return "just now"
|
|
|
|
elif age < 3600:
|
|
|
|
minutes = int(age / 60)
|
|
|
|
return f"{minutes}m ago"
|
|
|
|
elif age < 86400:
|
|
|
|
hours = int(age / 3600)
|
|
|
|
return f"{hours}hr ago"
|
|
|
|
elif age < 2678400:
|
|
|
|
days = int(age / 86400)
|
|
|
|
return f"{days}d ago"
|
|
|
|
|
|
|
|
now = time.gmtime()
|
|
|
|
ctd = time.gmtime(timestamp)
|
|
|
|
|
|
|
|
months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year)
|
|
|
|
if now.tm_mday < ctd.tm_mday:
|
|
|
|
months -= 1
|
|
|
|
|
|
|
|
if months < 12:
|
|
|
|
return f"{months}mo ago"
|
|
|
|
else:
|
|
|
|
years = int(months / 12)
|
|
|
|
return f"{years}yr ago"
|
|
|
|
|
|
|
|
|
2022-01-19 10:07:11 +00:00
|
|
|
@app.context_processor
|
|
|
|
def inject_constants():
|
2022-05-30 01:43:16 +00:00
|
|
|
return {"environ":environ, "SITE":SITE, "SITE_NAME":SITE_NAME, "SITE_FULL":SITE_FULL,
|
|
|
|
"AUTOJANNY_ID":AUTOJANNY_ID, "NOTIFICATIONS_ID":NOTIFICATIONS_ID, "PUSHER_ID":PUSHER_ID,
|
|
|
|
"CC":CC, "CC_TITLE":CC_TITLE, "listdir":listdir, "MOOSE_ID":MOOSE_ID, "AEVANN_ID":AEVANN_ID,
|
2022-06-24 15:08:57 +00:00
|
|
|
"PIZZASHILL_ID":PIZZASHILL_ID, "DEFAULT_COLOR":DEFAULT_COLOR,
|
2022-05-30 01:43:16 +00:00
|
|
|
"COLORS":COLORS, "ADMIGGERS":ADMIGGERS, "datetime":datetime, "time":time,
|
2022-06-26 01:01:21 +00:00
|
|
|
"HOLE_NAME": HOLE_NAME, "HOLE_STYLE_FLAIR": HOLE_STYLE_FLAIR, "HOLE_REQUIRED": HOLE_REQUIRED,
|
2022-06-23 09:02:49 +00:00
|
|
|
"LOTTERY_ENABLED": LOTTERY_ENABLED, "GUMROAD_LINK": GUMROAD_LINK,
|
2022-06-27 04:09:32 +00:00
|
|
|
"DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION,
|
|
|
|
"PROCOINS_ENABLED": PROCOINS_ENABLED,}
|