inital commit
This commit is contained in:
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