renamed the logger
This commit is contained in:
44
starface_call_logger.py
Normal file
44
starface_call_logger.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import sqlite3
|
||||
from flask import Flask, request
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
DB_FILE = "cleaning_logs.db"
|
||||
|
||||
def init_db():
|
||||
with sqlite3.connect(DB_FILE) as conn:
|
||||
conn.execute('''
|
||||
CREATE TABLE IF NOT EXISTS cleaning_events (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
room_number TEXT,
|
||||
cleaned_at TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
@app.route('/', methods=['POST'])
|
||||
def handle_post():
|
||||
# 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
|
||||
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# 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 cleaning_events (room_number, cleaned_at) VALUES (?, ?)",
|
||||
(room_number, timestamp)
|
||||
)
|
||||
|
||||
return f"Room {room_number} logged.", 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db()
|
||||
# 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