From 1d5578aafbe50d2dd7243942c809e0087c3d1f7b Mon Sep 17 00:00:00 2001 From: Bryan Cerrati Date: Thu, 19 Jun 2025 11:15:40 -0400 Subject: [PATCH] INIT COMMIT --- Dockerfile | 24 ++++++++++++ app/db/keepalive.db | Bin 0 -> 16384 bytes app/keep.py | 53 +++++++++++++++++++++++++++ app/templates/keepaliveshowpage.html | 32 ++++++++++++++++ app/templates/keepbase.html | 25 +++++++++++++ docker-compose.yml | 12 ++++++ requirements.txt | 2 + run.py | 16 ++++++++ teminalcommand.ps1 | 4 ++ 9 files changed, 168 insertions(+) create mode 100644 Dockerfile create mode 100644 app/db/keepalive.db create mode 100644 app/keep.py create mode 100644 app/templates/keepaliveshowpage.html create mode 100644 app/templates/keepbase.html create mode 100644 docker-compose.yml create mode 100644 requirements.txt create mode 100644 run.py create mode 100644 teminalcommand.ps1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62552cc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Use the official Python 3.9 slim image +FROM python:3.9-slim + +# Set the working directory +WORKDIR /app + +# Copy the requirements file and install dependencies +COPY requirements.txt ./ +RUN pip install --upgrade pip && pip install -r requirements.txt + +# Copy the rest of the application code +COPY . . + +# Set environment variables for production +ENV FLASK_ENV=production +ENV FLASK_APP=isalive.py +ENV FLASK_RUN_HOST=0.0.0.0 +ENV FLASK_RUN_PORT=5050 + +# Expose port 7000 (the internal port where the app will run) +EXPOSE 5050 + +# Use Gunicorn to serve the app on port 7000 +CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5050", "run:app"] diff --git a/app/db/keepalive.db b/app/db/keepalive.db new file mode 100644 index 0000000000000000000000000000000000000000..3c41ff96171a5f1f9a38cd5db1de6f77af7a7e47 GIT binary patch literal 16384 zcmeI&-AV#M6bJAb?E{6}Zo-R_#=TOC%3b?lud*0IDl6L{A&N<-T3R)8?B3p>cjyIr zvmT)t4YnlkHsn8g&^gB$_x$i?aL><<0wvj9`?)C;bIClRlB9>)|)W^6bs6zk(5P$##AOHafKmY;|fB*!vfF;QF!UF9t zDsdZ1CA-SR)P9whe9rvR-VtZEN!cuyOxQugPLwM?Kj78XWa6}1J}y;j?2y-Tro>7Y z{z9WM6nlf!xt3_kRlPFbUy9GB zvswBYAME)k<&y}57wJUrMlL=o{MCXTw(CL#?UtSJ`K7O$vKvClXr_W@G#lISkKdFz z>tjFw0uX=z1Rwwb2tWV=5P$##ATWUf=D&GreG>h|fB*y_009U<00Izz00bZa0SG`~ zLIhGYo~6+p2Gi#JuW$M%*8A`=A#I`!2tWV=5P$##AOHafKmY;|fWW^K@Rl=~C!y*O z?fahG*j{&b)}2CO%X3|?=nSv+YA%!cqr!itH@(d*&oK+uzS9M>kL$VHUcuGr^hmns H6?eV>AOnd? literal 0 HcmV?d00001 diff --git a/app/keep.py b/app/keep.py new file mode 100644 index 0000000..b9ebbaf --- /dev/null +++ b/app/keep.py @@ -0,0 +1,53 @@ +from flask import Blueprint, render_template, request, g +from datetime import datetime, date +import sqlite3 + + +keep = Blueprint('keep', __name__,template_folder='templates') + +def get_db(): + db = getattr(g, "_database", None) + if db is None: + db = g._database = sqlite3.connect("app/db/keepalive.db") + return db + +@keep.route('/keepalive/') +def dispkeepalive(): + conn = get_db() + c = conn.cursor() + items_from_db = c.execute("""SELECT + i.id, i.location, i.time, i.date + FROM + keepalive2 AS i + ORDER BY i.id DESC + """) + #db_teardown(keep) + items = [] + for row in items_from_db: + item = { + "id": row[0], + "location": row[1], + "time": row[2], + "date": row[3] + } + items.append(item) + + return render_template("keepaliveshowpage.html", items=items) + + +@keep.route('//', methods=["POST"]) +def getalive(location): + if request.method == "POST": + conn = get_db() + c = conn.cursor() + c.execute("""INSERT INTO keepalive2 + (location, date, time) + VALUES (?,?,?)""", + ( + location, + date.today().strftime("%m/%d/%y"), + datetime.now().strftime("%H:%M:%S") + ) + ) + conn.commit() + return location \ No newline at end of file diff --git a/app/templates/keepaliveshowpage.html b/app/templates/keepaliveshowpage.html new file mode 100644 index 0000000..f581718 --- /dev/null +++ b/app/templates/keepaliveshowpage.html @@ -0,0 +1,32 @@ +{% extends 'keepbase.html' %} + +{% block content %} + +{% if items %} + + + + + + + + + + + {% for item in items %} + + + + + + + {% endfor %} +{% else %} +

No items to show.

+{% endif %} + + +
LocationDateTime
{{ item.location }}{{ item.date }}{{ item.time }}
+ + +{% endblock %} \ No newline at end of file diff --git a/app/templates/keepbase.html b/app/templates/keepbase.html new file mode 100644 index 0000000..1e3a3e7 --- /dev/null +++ b/app/templates/keepbase.html @@ -0,0 +1,25 @@ + + + + + + + + + + {% block title %}{% endblock %} + + + + + + + + + +{% block content %}{% endblock %} + + + + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e38b901 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.8' +services: + web: + build: . + ports: + - "5050:5050" + environment: + - FLASK_ENV=production + - SECRET_KEY=youSCUMMER + volumes: + - .:/app + restart: always \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1167f2f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask +gunicorn \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 0000000..e0cd86d --- /dev/null +++ b/run.py @@ -0,0 +1,16 @@ +from flask import Flask, g +from app.keep import keep + + +app = Flask(__name__) +app.register_blueprint(keep) + + +@app.teardown_appcontext +def close_connection(exception): + db = getattr(g, "_database", None) + if db is not None: + db.close() + +if __name__ == "__main__": + app.run(host = "0.0.0.0", debug = True, port = 5050) \ No newline at end of file diff --git a/teminalcommand.ps1 b/teminalcommand.ps1 new file mode 100644 index 0000000..1a63bec --- /dev/null +++ b/teminalcommand.ps1 @@ -0,0 +1,4 @@ +$CurlArgument = '-X', 'POST', + 'http://24.185.75.128:8889/bay/' +$CURLEXE = 'C:\Program Files\Git\mingw64\bin\curl.exe' +& $CURLEXE @CurlArgument \ No newline at end of file