Add counts

This commit is contained in:
Sam W 2023-08-18 14:37:01 +02:00
parent 22ecb7c4ca
commit 0cdf3f4a98
2 changed files with 13 additions and 9 deletions

21
main.py
View File

@ -76,15 +76,18 @@ async def print():
subprocess.run(f"convert {png_filename} -resize 696x -background white -alpha remove -alpha off -monochrome -threshold 20% {png_filename}", shell=True, check=True)
#if not os.path.exists(quad_png_filename):
# subprocess.run("magick -size 696x xc:white ({png_filename} -resize 50%x)
printit(png_filename)
cur.execute("""INSERT OR REPLACE INTO counts(what, count)
VALUES (:what,
COALESCE(
(SELECT count FROM counts
WHERE what=:what),
0) + 1);
""", dict(what=lol))
db.commit()
for _ in range(int((await request.form)["count"])):
printit(png_filename)
cur.execute("""INSERT OR REPLACE INTO counts(what, count)
VALUES (:what,
COALESCE(
(SELECT count FROM counts
WHERE what=:what),
0) + 1);
""", dict(what=lol))
db.commit()
with open("counts.txt", "a") as f:
f.write(f"{lol}\n")
return redirect("/")
if __name__ == "__main__":

View File

@ -35,6 +35,7 @@
{{ counts.get(w.name, 0) }}
</div>
<form method="POST">
<input type="number" min="1" max="10" value="1" name="count">
<button type="submit" name="w" value="{{ w.name }}">Print</button>
</form>
</div>