Initial commit

This commit is contained in:
keystroke 2025-06-03 22:26:43 +10:00
commit 4efd2dc707
9 changed files with 86 additions and 0 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

24
LICENSE Normal file
View file

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# shopping-list
A simple list using Flask and a text file

Binary file not shown.

29
app.py Normal file
View file

@ -0,0 +1,29 @@
from flask import Flask, render_template, request, redirect, url_for
import os
app = Flask(__name__)
file_path = os.path.abspath(os.getcwd()) + '/list.txt'
@app.route("/")
def index():
with open(file_path, 'r') as file:
list = file.read().splitlines()
return render_template('index.html', list=list)
@app.route('/add', methods=['POST'])
def add():
item = request.form['item']
with open(file_path, 'a') as file:
file.write(item + '\n')
return redirect(url_for('index'))
@app.route('/remove', methods=['POST'])
def remove():
item = request.form['item']
with open(file_path, 'r+') as file:
list = file.read().splitlines()
list.remove(item)
file.seek(0)
file.writelines([item + '\n' for item in list])
file.truncate()
return redirect(url_for('index'))

1
list.txt Normal file
View file

@ -0,0 +1 @@
hello cruel world

BIN
static/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

0
static/style.css Normal file
View file

28
templates/index.html Normal file
View file

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>shopping-list</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
<link rel="shortcut icon" type="image/ico" href="{{ url_for('static', filename='icon.ico') }}">
</head>
<body>
<ul>
{%- for item in list %}
<li>
<form action="{{ url_for('remove') }}" method="POST">
<input type="submit" value="-" class="button">
<label>{{ item }}</label>
<input type="hidden" name="item" value="{{ item }}">
</form>
</li>
{%- endfor %}
</ul>
<form action="{{ url_for('add') }}" method="POST">
<input type="text" name="item" autocomplete="off" autofocus>
<input type="submit" value="+" class="button">
</form>
</body>
</html>