minetest-telegram-bridge/bot/server.py

38 lines
831 B
Python
Raw Normal View History

2019-01-22 11:36:54 +01:00
#!/usr/bin/env python3
2019-01-22 13:16:00 +01:00
from flask import Flask, request
2019-01-22 11:36:54 +01:00
import sqlite3
def get(db):
2019-01-22 13:16:00 +01:00
cursor = db.cursor()
query = "SELECT * FROM messages ORDER BY ROWID"
cursor.execute(query)
text = ""
for row in cursor:
text += row[0] + "\n"
cursor.execute("DELETE FROM messages")
db.commit()
return text
2019-01-22 11:36:54 +01:00
def post(db):
2019-01-22 13:16:00 +01:00
message = request.form['message']
cursor = db.cursor()
query = 'INSERT INTO messages values(?)'
cursor.execute(query, (message,))
db.commit()
return ""
2019-01-22 11:36:54 +01:00
app = Flask(__name__)
db = sqlite3.connect(":memory:", check_same_thread=False)
# Set up tables
cursor = db.cursor()
with open('schema.sql') as fp:
cursor.executescript(fp.read())
app.add_url_rule('/get', 'get', lambda: get(db))
app.add_url_rule('/post', 'post', lambda: post(db), methods=["POST"])