From 2a0d3c4ccb287282974856b5f20f67a078149cb8 Mon Sep 17 00:00:00 2001 From: jwansek Date: Sat, 6 Mar 2021 21:51:06 +0000 Subject: added dockerfile, similar thoughts --- Dockerfile | 9 +++++++++ app.py | 18 ++++++++++++++---- database.py | 14 ++++++++++---- example.conf | 5 ++++- requirements.txt | 4 ++++ static/images/shark1.jpg | Bin 0 -> 449065 bytes static/images/shark2.jpg | Bin 0 -> 433903 bytes static/index.md | 2 +- static/style.css | 9 +++++++-- templates/index.html | 2 +- templates/template.html | 9 ++++++++- templates/thoughts.html | 2 +- 12 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 Dockerfile create mode 100644 static/images/shark1.jpg create mode 100644 static/images/shark2.jpg diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9d0fa4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:latest +MAINTAINER Eden Attenborough "eda@e.email" +RUN apt-get update -y +RUN apt-get install -y python3-pip python-dev build-essential +COPY . /app +WORKDIR /app +RUN pip3 install -r requirements.txt +ENTRYPOINT ["python3"] +CMD ["app.py", "--production"] \ No newline at end of file diff --git a/app.py b/app.py index b187f3e..a7784dd 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,5 @@ +from paste.translogger import TransLogger +from waitress import serve from PIL import Image import configparser import webbrowser @@ -7,6 +9,7 @@ import services import random import parser import flask +import sys import os import io @@ -94,7 +97,8 @@ def get_thought(): thought = True, dt = "published: " + str(dt), category = category_name, - othercategories = db.get_categories_not(category_name) + othercategories = db.get_categories_not(category_name), + related = db.get_similar_thoughts(category_name, thought_id) ) @app.route("/thoughts") @@ -161,13 +165,12 @@ def serve_api_request(infoRequest): else: flask.abort(404) - @app.route("/preview") def preview(): if "PREVIEW" in os.environ: with database.Database() as db: return flask.render_template_string( - os.environ["PREVIEW"], + '{% extends "template.html" %}\n{% block content %}\n' + os.environ["PREVIEW"] + '\n{% endblock %}', **get_template_items(os.environ["PREVIEW_TITLE"], db), thought = True, dt = "preview rendered: " + str(datetime.datetime.now()), @@ -178,4 +181,11 @@ def preview(): flask.abort(404) if __name__ == "__main__": - app.run(host = "0.0.0.0", debug = True) \ No newline at end of file + try: + if sys.argv[1] == "--production": + #serve(TransLogger(app), host='127.0.0.1', port = 6969) + serve(TransLogger(app), host='0.0.0.0', port = 6969) + else: + app.run(host = "0.0.0.0", port = 5001, debug = True) + except IndexError: + app.run(host = "0.0.0.0", port = 5001, debug = True) \ No newline at end of file diff --git a/database.py b/database.py index 06dc34d..bb870b8 100644 --- a/database.py +++ b/database.py @@ -91,6 +91,15 @@ class Database: WHERE thought_id = %s;""", (id_, )) return cursor.fetchone() + def get_similar_thoughts(self, category, id_): + with self.__connection.cursor() as cursor: + cursor.execute(""" + SELECT thought_id, title, dt, category_name FROM thoughts + INNER JOIN categories ON thoughts.category_id = categories.category_id + WHERE category_name = %s AND thought_id != %s;""", + (category, id_)) + return cursor.fetchall() + def get_featured_thoughts(self): with self.__connection.cursor() as cursor: cursor.execute("SELECT thought_id, title FROM thoughts WHERE featured = 1;") @@ -223,8 +232,5 @@ def request_recent_commits(since = datetime.datetime.now() - datetime.timedelta( return sorted(out, key = lambda a: a["datetime"], reverse = True) if __name__ == "__main__": - import datetime - start = datetime.datetime.now() with Database() as db: - print(db.get_cached_tweets()) - print("Took: ", (datetime.datetime.now() - start)) \ No newline at end of file + print(db.get_similar_thoughts("about me", 5)) \ No newline at end of file diff --git a/example.conf b/example.conf index bd16037..1cec18f 100644 --- a/example.conf +++ b/example.conf @@ -29,4 +29,7 @@ user = admin passwd = *********** [discord] -username = @jwnskanzkwk#9757 \ No newline at end of file +username = @jwnskanzkwk#9757 + +[github] +access_code = ******************************************* \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3644402..07cf1bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,7 @@ PiHole-api Pillow==8.1.0 python-qbittorrent==0.4.2 PyGithub +lxml +requests +PasteScript==3.2.0 +waitress diff --git a/static/images/shark1.jpg b/static/images/shark1.jpg new file mode 100644 index 0000000..394846c Binary files /dev/null and b/static/images/shark1.jpg differ diff --git a/static/images/shark2.jpg b/static/images/shark2.jpg new file mode 100644 index 0000000..2c432cd Binary files /dev/null and b/static/images/shark2.jpg differ diff --git a/static/index.md b/static/index.md index e217a94..31707a7 100644 --- a/static/index.md +++ b/static/index.md @@ -1,4 +1,4 @@ -# haii +# haiiiiiii my name is eden and im a 19yo computer science undergraduate. i made my own website to encourage others to do so too. i'll post my thoughts on here sometimes, and use this site to link to other stuff i host. diff --git a/static/style.css b/static/style.css index 26b337c..0e77ec0 100644 --- a/static/style.css +++ b/static/style.css @@ -100,6 +100,10 @@ article section table td { max-width: 65%; } +article img { + max-width: 65%; +} + aside { width: 30%; padding-left: 15px; @@ -132,8 +136,9 @@ body div article { } footer { - background-color: gray; - padding: 3px; + padding: 300px 10px 5px 20px; + margin-bottom: 300px; + font-size: xx-small; } @media (max-width: 1023px) { diff --git a/templates/index.html b/templates/index.html index fd0bae1..91f7ded 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@

recent thoughts:

diff --git a/templates/template.html b/templates/template.html index fd65cdb..d72cd0f 100644 --- a/templates/template.html +++ b/templates/template.html @@ -45,6 +45,12 @@ +
related thoughts:
+
other categories:
{% for category_name in othercategories %}