diff --git a/app.py b/app.py index d5078cb..2332b25 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,4 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Wed May 20 12:52:00 2026 - -@author: angoosh -""" -from flask import Flask, render_template_string, redirect, url_for +from flask import Flask, render_template_string, jsonify import sqlite3 app = Flask(__name__) @@ -15,18 +8,22 @@ def init_db(): """Initialize the database and set the starting number to 0 if it doesn't exist.""" with sqlite3.connect(DB_FILE) as conn: c = conn.cursor() - # Create a table to hold our counter - c.execute('CREATE TABLE IF NOT EXISTS counter (id INTEGER PRIMARY KEY, value INTEGER)') - # Check if the counter row already exists + # 1. Setup Button Counter Table + c.execute('CREATE TABLE IF NOT EXISTS counter (id INTEGER PRIMARY KEY, value INTEGER)') c.execute('SELECT value FROM counter WHERE id = 1') if c.fetchone() is None: - # If not, insert the initial value of 0 c.execute('INSERT INTO counter (id, value) VALUES (1, 0)') + + # 2. Setup Visit Counter Table + c.execute('CREATE TABLE IF NOT EXISTS visits (id INTEGER PRIMARY KEY, count INTEGER)') + c.execute('SELECT count FROM visits WHERE id = 1') + if c.fetchone() is None: + c.execute('INSERT INTO visits (id, count) VALUES (1, 0)') + conn.commit() -# HTML & CSS template -# The CSS handles making the button blue and centering the layout +# We added an ID to the counter div and a JavaScript block at the bottom HTML_TEMPLATE = ''' @@ -35,10 +32,22 @@ HTML_TEMPLATE = '''