aboutsummaryrefslogtreecommitdiffstats
path: root/app.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2021-03-03 22:26:16 +0000
committerjwansek <eddie.atten.ea29@gmail.com>2021-03-03 22:26:16 +0000
commit5d330852b8b390af41717e0fdb47a689cc18bd77 (patch)
tree7da24066420ccbd418fe60ca308635dca94bfc47 /app.py
parenta36992b08c7e165b271ac76166058db2c50609fe (diff)
downloadboymoder.blog-5d330852b8b390af41717e0fdb47a689cc18bd77.tar.gz
boymoder.blog-5d330852b8b390af41717e0fdb47a689cc18bd77.zip
updated loads of shit
Diffstat (limited to 'app.py')
-rw-r--r--app.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/app.py b/app.py
index 24a6c64..5978281 100644
--- a/app.py
+++ b/app.py
@@ -4,6 +4,7 @@ import webbrowser
import datetime
import database
import services
+import random
import parser
import flask
import os
@@ -12,13 +13,35 @@ import io
app = flask.Flask(__name__)
CONFIG = configparser.ConfigParser()
CONFIG.read("edaweb.conf")
+shown_images = set()
+
+def get_pfp_img(db:database.Database):
+ global shown_images
+ dbimg = db.get_pfp_images()
+ if len(shown_images) == len(dbimg):
+ shown_images = set()
+ folder = set(dbimg).difference(shown_images)
+ choice = random.choice(list(folder))
+ shown_images.add(choice)
+ return choice
+
+def get_correct_article_headers(db:database.Database, title):
+ db_headers = list(db.get_header_articles())
+ if title in [i[0] for i in db_headers]:
+ out = []
+ for i in db_headers:
+ if i[0] != title:
+ out.append(i)
+ return out + [("index", "/")]
+ else:
+ return db_headers + [("index", "/")]
def get_template_items(title, db):
return {
"links": db.get_header_links(),
- "image": db.get_pfp_image(),
+ "image": get_pfp_img(db),
"title": title,
- "articles": db.get_header_articles()
+ "articles": get_correct_article_headers(db, title)
}
@app.route("/")
@@ -26,7 +49,7 @@ def index():
with database.Database() as db:
return flask.render_template(
"index.html",
- **get_template_items("edaweb.co.uk", db)
+ **get_template_items("eda.gay", db)
)
@app.route("/discord")
@@ -54,7 +77,11 @@ def serve_services():
def get_thought():
thought_id = flask.request.args.get("id", type=int)
with database.Database() as db:
- category_name, title, dt, parsed = parser.get_thought_from_id(db, thought_id)
+ try:
+ category_name, title, dt, parsed = parser.get_thought_from_id(db, thought_id)
+ except TypeError:
+ flask.abort(404)
+ return
return flask.render_template_string(
parsed,
**get_template_items(title, db),
@@ -121,4 +148,4 @@ def preview():
if __name__ == "__main__":
- app.run(host = "0.0.0.0", debug = True)
+ app.run(host = "0.0.0.0", debug = True) \ No newline at end of file