fixed most of the issues i could find with to little sleep
This commit is contained in:
35
test.py
35
test.py
@@ -3,37 +3,42 @@ from flask import Flask, request
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
DB_FILE = "logs.db"
|
||||
DB_FILE = "cleaning_logs.db"
|
||||
|
||||
def init_db():
|
||||
with sqlite3.connect(DB_FILE) as conn:
|
||||
conn.execute('''
|
||||
CREATE TABLE IF NOT EXISTS post_logs (
|
||||
CREATE TABLE IF NOT EXISTS cleaning_events (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp TEXT,
|
||||
content_type TEXT,
|
||||
body TEXT
|
||||
room_number TEXT,
|
||||
cleaned_at 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()
|
||||
# Extract the room number from the POST body
|
||||
# .strip('"') removes extra quotes if the sender includes them
|
||||
room_number = request.get_data(as_text=True).strip().strip('"')
|
||||
|
||||
if not room_number:
|
||||
return "Missing room number", 400
|
||||
|
||||
# Log to Console
|
||||
print(f"[{timestamp}] Logging POST: {body[:50]}...")
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# Log to SQLite
|
||||
# Log to Console for your visibility
|
||||
print(f"Room {room_number} marked as cleaned at {timestamp}")
|
||||
|
||||
# Save to SQLite
|
||||
with sqlite3.connect(DB_FILE) as conn:
|
||||
conn.execute(
|
||||
"INSERT INTO post_logs (timestamp, content_type, body) VALUES (?, ?, ?)",
|
||||
(timestamp, content_type, body)
|
||||
"INSERT INTO cleaning_events (room_number, cleaned_at) VALUES (?, ?)",
|
||||
(room_number, timestamp)
|
||||
)
|
||||
|
||||
return "Logged successfully", 200
|
||||
return f"Room {room_number} logged.", 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db()
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
# Binding to 0.0.0.0 so devices on your network can reach it
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
|
||||
Reference in New Issue
Block a user