From 5d330852b8b390af41717e0fdb47a689cc18bd77 Mon Sep 17 00:00:00 2001 From: jwansek Date: Wed, 3 Mar 2021 22:26:16 +0000 Subject: updated loads of shit --- .gitignore | 1 + app.py | 37 ++++++++++++++++++++++++++++++++----- database.py | 19 ++++++++++--------- static/images/telegrampic2.jpg | Bin 0 -> 25752 bytes static/style.css | 10 ++++++++-- 5 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 static/images/telegrampic2.jpg diff --git a/.gitignore b/.gitignore index f2583ac..aed6835 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ !README.md edaweb.conf +markdowns/ *.md # Byte-compiled / optimized / DLL files 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 diff --git a/database.py b/database.py index 142d942..6bf3c1f 100644 --- a/database.py +++ b/database.py @@ -1,7 +1,7 @@ from dataclasses import dataclass +import configparser import pymysql import random -import app @dataclass class Database: @@ -10,17 +10,20 @@ class Database: passwd:str = None def __enter__(self): + config = configparser.ConfigParser() + config.read("edaweb.conf") + if self.safeLogin: self.__connection = pymysql.connect( - **app.CONFIG["mysql"], + **config["mysql"], charset = "utf8mb4" ) else: self.__connection = pymysql.connect( user = self.user, passwd = self.passwd, - host = app.CONFIG["mysql"]["host"], - db = app.CONFIG["mysql"]["db"], + host = config["mysql"]["host"], + db = config["mysql"]["db"], charset = "utf8mb4" ) return self @@ -38,10 +41,10 @@ class Database: cursor.execute("SELECT alt, url FROM images WHERE imageName = %s;", (imageName, )) return cursor.fetchone() - def get_pfp_image(self): + def get_pfp_images(self): with self.__connection.cursor() as cursor: cursor.execute("SELECT alt, url FROM images WHERE pfp_img = 1;") - return random.choice(cursor.fetchall()) + return cursor.fetchall() def get_header_articles(self): with self.__connection.cursor() as cursor: @@ -94,8 +97,6 @@ class Database: """) return cursor.fetchall() - - if __name__ == "__main__": with Database() as db: - print(db.get_all_thoughts()) \ No newline at end of file + print(db.get_header_articles()) \ No newline at end of file diff --git a/static/images/telegrampic2.jpg b/static/images/telegrampic2.jpg new file mode 100644 index 0000000..8b306ff Binary files /dev/null and b/static/images/telegrampic2.jpg differ diff --git a/static/style.css b/static/style.css index 7a0bf68..93ec3ed 100644 --- a/static/style.css +++ b/static/style.css @@ -1,6 +1,7 @@ html { background-color: black; - font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif; + font-family: 'Open Sans', sans-serif; + font-size: small; } body { @@ -21,7 +22,7 @@ body { } header { - background-color: #8fbce7; + background-color: #f1f3f3; } @@ -51,6 +52,11 @@ header span nav ul li a { color: white; } +header div { + padding-left: 30px; + padding-bottom: 10px; +} + nav ul { margin: 0; padding: 0; -- cgit v1.2.3