diff --git a/.dockerignore b/.dockerignore index 1d1fe94..9414382 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1 @@ -Dockerfile \ No newline at end of file +Dockerfile diff --git a/lunchbot/templates/index.html b/lunchbot/templates/index.html index 3693240..fb71ad7 100644 --- a/lunchbot/templates/index.html +++ b/lunchbot/templates/index.html @@ -92,4 +92,4 @@

Logs:

- \ No newline at end of file + diff --git a/lunchbot/website.py b/lunchbot/website.py deleted file mode 100644 index 6419e61..0000000 --- a/lunchbot/website.py +++ /dev/null @@ -1,67 +0,0 @@ -from flask import Flask, session, render_template, request -import json -import os -from flask_session import Session -from apscheduler.schedulers.background import BackgroundScheduler -import subprocess -import atexit - -app = Flask(__name__) - -# Set the secret key to some random bytes. Keep this really secret! -app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' - -# Set Flask session options -app.config['SESSION_TYPE'] = 'filesystem' -Session(app) - -logs = [] - -def run_script(): - # result = subprocess.run(['python', 'scripts/run_lunchbot.py', '>', '/tmp/lunchbot_run_logs.txt'], capture_output=True, shell=True) - # os.system('python scripts/run_lunchbot.py > /tmp/lunchbot_run_logs.txt') - # change to directory one level up, then run setup.sh, and then the run_lunchbot.py script - os.system('bash -c "source setup.sh && python scripts/run_lunchbot.py &>> /tmp/lunchbot_run_logs.txt"') - # logs.append(result.stdout) - with open("/tmp/lunchbot_run_logs.txt") as f: - logs.append(f.read()) - -scheduler = BackgroundScheduler() -# scheduler.add_job(func=run_script, trigger="interval", minutes=5) -scheduler.start() - -# Shut down the scheduler when exiting the app -atexit.register(lambda: scheduler.shutdown()) - -@app.route('/run-script', methods=['POST']) -def run_script_route(): - run_script() - return ('', 204) - - -@app.route('/send-message', methods=['POST']) -def send_message_route(): - data = json.loads(request.data) - message = data['message'] - os.system(f'python scripts/send_message.py --message "{message}"') - return ('', 204) - -@app.route('/logs') -def logs_route(): - with open("/tmp/lunchbot_run_logs.txt") as f: - return f.read() - -@app.route('/') -def home(): - if 'counter' not in session: - session['counter'] = 0 - else: - session['counter'] += 1 - return render_template('index.html', counter=session['counter'], logs=logs) - -if __name__ == "__main__": - # create logs file - with open("/tmp/lunchbot_run_logs.txt", "w") as f: - f.write("Lunchbot logs\n") - app.run(debug=True, host="0.0.0.0", port=8080) - # run_script() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0d718dc..7aaaf75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,4 @@ pre-commit python-dotenv requests ruff -selenium \ No newline at end of file +selenium diff --git a/scripts/run_lunchbot.py b/scripts/run_lunchbot.py index 094337f..e99bab6 100644 --- a/scripts/run_lunchbot.py +++ b/scripts/run_lunchbot.py @@ -270,7 +270,7 @@ def main(): # add which canteen + "|" + " | ".join([dish["canteen"] for dish in list_of_dishes]) + " |\n" # add the images - + "|" + " | ".join([f" ![preview {dish['generation_info_tag']}]({dish['image_url']} =200)" + + "|" + " | ".join([f" ![preview {dish['generation_info_tag']}]({dish['image_url']} =200)" for dish in list_of_dishes]) + " |\n" ) # fmt: on diff --git a/scripts/run_website.sh b/scripts/run_website.sh index 6845820..1821f30 100755 --- a/scripts/run_website.sh +++ b/scripts/run_website.sh @@ -4,4 +4,4 @@ # i.e. do ./scripts/run_website.sh in the root of the repo source setup.sh -python lunchbot/website.py \ No newline at end of file +python lunchbot/website.py diff --git a/scripts/send_message.py b/scripts/send_message.py index dcb58c6..d712be9 100644 --- a/scripts/send_message.py +++ b/scripts/send_message.py @@ -1,7 +1,5 @@ import logging import os -from subprocess import run # nosec -from urllib import request # nosec import argparse from dotenv import load_dotenv @@ -46,4 +44,4 @@ def main(message): if __name__ == "__main__": args = parser.parse_args() - main(message=args.message) \ No newline at end of file + main(message=args.message) diff --git a/setup.sh b/setup.sh index e8298ca..139deaf 100755 --- a/setup.sh +++ b/setup.sh @@ -2,4 +2,4 @@ source .env source /app/venv_container/bin/activate -export PYTHONPATH=$PWD:$PYTHONPATH \ No newline at end of file +export PYTHONPATH=$PWD:$PYTHONPATH