From c0725f614a886830cab954eb5bd043a2817094bf Mon Sep 17 00:00:00 2001 From: pk13274 Date: Sun, 23 Mar 2025 23:33:47 +0000 Subject: [PATCH] Upload files to "/" --- app.py | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..5516b46 --- /dev/null +++ b/app.py @@ -0,0 +1,163 @@ +from flask import Flask, render_template_string, request + +app = Flask(__name__) + +# Define the HTML template for the list +HTML_TEMPLATE = ''' + + + + + Chris/Alice Master/Kitten Contract (Read Only) + + + +

Master Chris

+

Kitten Alice

+

Contract

+ + +
+ + +
+ + + + +''' + +# Define the HTML template for the editable list +READ_ONLY_HTML_TEMPLATE = ''' + + + + + Chris/Alice Master/Kitten Contract + + + +

Master Chris

+

Kitten Alice

+

Contract

+ + + + + +''' + +# Function to read the list from a file +def read_list(): + try: + with open('list.txt', 'r') as file: + return [line.strip() for line in file.readlines()] + except FileNotFoundError: + return [] + +# Function to write the list to a file +def write_list(items): + with open('list.txt', 'w') as file: + for item in items: + file.write(f"{item}\n") + +@app.route('/') +def manage(): + items = read_list() + return render_template_string(READ_ONLY_HTML_TEMPLATE, items=items) + +@app.route('/add', methods=['POST']) +def add_item(): + data = request.get_json() + new_item = data['item'] + items = read_list() + items.append(new_item) + write_list(items) + return '', 204 + +@app.route('/delete/', methods=['DELETE']) +def delete_item(index): + items = read_list() + if index < len(items): + del items[index] + write_list(items) + return '', 204 + +@app.route('/manage/') +def manage_read_only(): + items = read_list() + return render_template_string(HTML_TEMPLATE, items=items) + +if __name__ == '__main__': + app.run(debug=True, host='0.0.0.0', port=5000)