commit 4b3c50599c3f96d0482978480fdae65b0918cc1c Author: Kendrick Bollens Date: Thu Jan 29 23:45:01 2026 +0100 inital commit diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6f6bfa6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1769461804, + "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c6d510c --- /dev/null +++ b/flake.nix @@ -0,0 +1,28 @@ +{ + description = "Python Flask environment with SQLite support"; + + inputs = { + nixpkgs.url = "github:nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.sqlite-interactive + (pkgs.python3.withPackages (ps: [ ps.flask ])) + ]; + + shellHook = '' + echo "--- Flask + SQLite Environment ---" + echo "To view logs: sqlite3 logs.db 'SELECT * FROM post_logs;'" + ''; + }; + } + ); +} diff --git a/test.py b/test.py new file mode 100644 index 0000000..7f5d4ea --- /dev/null +++ b/test.py @@ -0,0 +1,39 @@ +import sqlite3 +from flask import Flask, request +from datetime import datetime + +app = Flask(__name__) +DB_FILE = "logs.db" + +def init_db(): + with sqlite3.connect(DB_FILE) as conn: + conn.execute(''' + CREATE TABLE IF NOT EXISTS post_logs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + timestamp TEXT, + content_type TEXT, + body TEXT + ) + ''') + +@app.route('/', methods=['POST']) +def handle_post(): + content_type = request.headers.get('Content-Type') + body = request.get_data(as_text=True) + timestamp = datetime.now().isoformat() + + # Log to Console + print(f"[{timestamp}] Logging POST: {body[:50]}...") + + # Log to SQLite + with sqlite3.connect(DB_FILE) as conn: + conn.execute( + "INSERT INTO post_logs (timestamp, content_type, body) VALUES (?, ?, ?)", + (timestamp, content_type, body) + ) + + return "Logged successfully", 200 + +if __name__ == '__main__': + init_db() + app.run(host='0.0.0.0', port=5000, debug=True)