From c172cafdbc0e969609275cab92b9a7bd2091f0b0 Mon Sep 17 00:00:00 2001 From: 0x01FE <0x10FE@0x01fe.net> Date: Thu, 14 Mar 2024 10:34:33 -0500 Subject: [PATCH 1/2] added some stuff for running on my server --- .gitignore | 3 +++ Dockerfile | 2 +- app/{website.py => app.py} | 12 +++++++++--- app/resources/status.text | 2 +- config.ini | 5 +++-- requirements.txt | 4 +++- 6 files changed, 20 insertions(+), 8 deletions(-) rename app/{website.py => app.py} (82%) diff --git a/.gitignore b/.gitignore index 2ed48ce..4028b36 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ __pycache__ *.md !POST_TEMPLATE.md !README.md + +docker-compose.yaml +*.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 963ed85..6a5b9c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,4 @@ RUN python3 -m pip install -r requirements.txt WORKDIR ./app -CMD ["python3", "-u", "./app.py"] +CMD ["python3", "-u", "app.py"] diff --git a/app/website.py b/app/app.py similarity index 82% rename from app/website.py rename to app/app.py index e0976ba..9d2c99f 100644 --- a/app/website.py +++ b/app/app.py @@ -3,6 +3,7 @@ import configparser import random import flask +import waitress from post import Post @@ -14,10 +15,12 @@ config.read(CONFIG_PATH) POSTS_FOLDER = config['POSTS']['POSTS_FOLDER'] STATUS_FILE = config['STATUS']['STATUS_FILE'] +PORT = int(config['NETWORK']['PORT']) +DEV = int(config['NETWORK']['DEV']) def get_posts(category_filter : str | None = None) -> list[Post]: - post_files= glob.glob(f'{POSTS_FOLDER}/*') - post_files.remove(f'{POSTS_FOLDER}\\POST_TEMPLATE.md') + post_files = glob.glob(f'{POSTS_FOLDER}/*') + post_files.remove(f'{POSTS_FOLDER}/POST_TEMPLATE.md') posts: list[Post] = [] for post_file in post_files: @@ -67,4 +70,7 @@ def index(): if __name__ == "__main__": - app.run() + if DEV: + app.run(port=PORT) + else: + waitress.serve(app, host='0.0.0.0', port=PORT) diff --git a/app/resources/status.text b/app/resources/status.text index a00b8ec..af19294 100644 --- a/app/resources/status.text +++ b/app/resources/status.text @@ -25,4 +25,4 @@ What do you mean ... You can't see it? I don't believe you, your eyes deceive you, better check yourself in You will say I'm crazy, I will go on my way 'cause it's what I need I'd cross a thousand seas just to prove I'm not mad -I thoguht I saw a statue blink, and a bird with no head, Land on a golden thread, I rub my eyes, What am I saying? There's nothing there \ No newline at end of file +I thought I saw a statue blink, and a bird with no head, Land on a golden thread, I rub my eyes, What am I saying? There's nothing there \ No newline at end of file diff --git a/config.ini b/config.ini index 63cc0da..8bc9e69 100644 --- a/config.ini +++ b/config.ini @@ -1,8 +1,9 @@ [POSTS] -posts_folder=./posts +posts_folder=posts [STATUS] -status_file=./resources/status.text +status_file=resources/status.text [NETWORK] +DEV=0 PORT=1111 diff --git a/requirements.txt b/requirements.txt index 67443c6..1308c6c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ Markdown==3.5.2 -Flask==2.2.3 \ No newline at end of file +Flask==2.2.3 +waitress==2.1.2 +Werkzeug==2.2.3 \ No newline at end of file From 79c5fc95a7421fee56ec29953ae1e93a8d58d690 Mon Sep 17 00:00:00 2001 From: 0x01FE <0x10FE@0x01fe.net> Date: Thu, 14 Mar 2024 10:39:43 -0500 Subject: [PATCH 2/2] i messed up the merge --- app/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/app.py b/app/app.py index 099bc73..82cf16f 100644 --- a/app/app.py +++ b/app/app.py @@ -47,12 +47,12 @@ def get_posts(category_filter : str | None = None) -> list[Post]: return reversed(ordered_posts) def get_status() -> str: - with open(STATUS_FILE, 'r') as file: + with open(STATUS_FILE, 'r', encoding='utf-8') as file: statuses = file.readlines() status = random.randint(0, len(statuses) - 1) - return statuses[status] + return markdown.markdown(statuses[status]) @app.route('/') def index():