status_server.py 738 B

123456789101112131415161718192021
  1. from datetime import datetime
  2. from flask import Flask, request
  3. from sqlalchemy import create_engine
  4. app = Flask(__name__)
  5. filename = "access.log"
  6. engine = create_engine("mysql+pymysql://gaps:Gcbs12ma@192.168.2.41/status")
  7. @app.route("/ping/<kunde>")
  8. def ping(kunde):
  9. uptime = int(request.args.get("uptime", "0"))
  10. current_date = datetime.now().timestamp()
  11. print(kunde + " hat sich um " + str(current_date) + " gemeldet")
  12. with open(filename, "a") as f:
  13. f.write(str(current_date) + ";" + kunde + "\n")
  14. with engine.connect() as con:
  15. query = f"INSERT INTO ping (kunde, pingtime, uptime) VALUES ('{kunde}', '{int(current_date)}', '{uptime}')"
  16. con.execute(query)
  17. return "Hallo " + kunde + "!"