Files
Raumreinigung-Logger/test.py
Kendrick Bollens 4b3c50599c inital commit
2026-01-29 23:45:01 +01:00

40 lines
1.0 KiB
Python

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)