瀏覽代碼

Upload files to ''

Initial commit
deadtom 1 天之前
父節點
當前提交
4b48f3b240
共有 5 個文件被更改,包括 96 次插入1 次删除
  1. 0 1
      README.md
  2. 54 0
      app.py
  3. 25 0
      list.html
  4. 8 0
      pyproject.toml
  5. 9 0
      wsgi.py

+ 0 - 1
README.md

@@ -5,4 +5,3 @@ A web based app to add and check items off a list, which outputs a page that can
 ## Run with:
  
 ```.venv/bin/python -m gunicorn -b 0.0.0.0:8043 -w 1 'app:app'
-

+ 54 - 0
app.py

@@ -0,0 +1,54 @@
+from flask import Flask, render_template, request, redirect, url_for
+import json
+import os
+
+app = Flask(__name__)
+
+# File to store checklist items
+CHECKLIST_FILE = 'checklist.json'
+
+
+# Load checklist items from a file
+def load_checklist():
+    if os.path.exists(CHECKLIST_FILE):
+        with open(CHECKLIST_FILE, 'r') as file:
+            return json.load(file)
+    return []
+
+
+# Save checklist items to a file
+def save_checklist(items):
+    with open(CHECKLIST_FILE, 'w') as file:
+        json.dump(items, file)
+
+
+# In-memory storage for checklist items
+checklist_items = load_checklist()
+
+
+@app.route('/', methods=['GET', 'POST'])
+def index():
+    if request.method == 'POST':
+        item = request.form.get('item')
+        if item:
+            checklist_items.append({'name': item, 'checked': False})
+            save_checklist(checklist_items)  # Save to file after adding
+        return redirect(url_for('index'))
+    return render_template('index.html', items=checklist_items)
+
+
+@app.route('/check/<int:item_id>')
+def check(item_id):
+    if 0 <= item_id < len(checklist_items):
+        checklist_items[item_id]['checked'] = not checklist_items[item_id]['checked']
+        save_checklist(checklist_items)  # Save to file after checking
+    return redirect(url_for('index'))
+
+
+@app.route('/list')
+def list():
+    return render_template('list.html', items=checklist_items)
+
+
+if __name__ == '__main__':
+    app.run(debug=True)

+ 25 - 0
list.html

@@ -0,0 +1,25 @@
+ 
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Today's to-do List</title>
+    <style>
+        body {
+            background-color: transparent;
+            color: black;
+        }
+    </style>
+</head>
+<body>
+    <h1>Today's to-do List</h1>
+    <ul>
+        {% for item in items %}
+            <li style="text-decoration: {{ 'line-through' if item.checked else 'none' }};">
+                {{ item.name }}
+            </li>
+        {% endfor %}
+    </ul>
+</body>
+</html>

+ 8 - 0
pyproject.toml

@@ -0,0 +1,8 @@
+[build-system]
+requires = ["setuptools>=42", "wheel"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "checklist"
+version = "0.1"
+dependencies = ["flask", "gunicorn"]

+ 9 - 0
wsgi.py

@@ -0,0 +1,9 @@
+import sys
+import os
+import logging
+
+current_dir = os.path.dirname(os.path.abspath(__file__))
+pathtoapp = os.path.join(current_dir, 'checklist')  # Adjust this if your app is in a different folder
+sys.path.insert(0, pathtoapp)
+
+from app import app as application