inital commit
This commit is contained in:
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@@ -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
|
||||||
|
}
|
||||||
28
flake.nix
Normal file
28
flake.nix
Normal file
@@ -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;'"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
39
test.py
Normal file
39
test.py
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user