You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

  1. from flask import Flask, render_template, send_from_directory
  2. from flask_socketio import SocketIO, emit
  3. import os
  4. import json
  5. app = Flask(__name__)
  6. app.config['SECRET_KEY'] = 'yigit007'
  7. socketio = SocketIO(app)
  8. src_path , file_list = "../server_side/api/modules/databases/",["denunciations","complaints"]
  9. changed = {}
  10. for file in file_list:
  11. changed[file] = os.stat(os.path.join(src_path,file+".json"))
  12. def file_check(file):
  13. src = os.path.join(src_path,file+".json")
  14. if changed[file] != os.stat(src):
  15. print("[INFO]: Changed " + file)
  16. changed[file] = os.stat(src)
  17. with open(src,"r") as f:
  18. json_data = json.loads(f.read())
  19. return True,json.dumps(json_data)
  20. return False,""
  21. @socketio.on("check",namespace="/denunciations_socket")
  22. def denunciation_handle(msg):
  23. change,data = file_check("denunciations")
  24. if change:
  25. emit("new", data, namespace="/denunciations_socket")
  26. @socketio.on('connect', namespace='/denunciations_socket')
  27. def handle_my_custom_namespace_event():
  28. print("[INFO]: Received socket connection!")
  29. src = os.path.join(src_path,"denunciations.json")
  30. with open(src,"r") as f:
  31. json_data = json.loads(f.read())
  32. emit("new", json.dumps(json_data), namespace="/denunciations_socket")
  33. @app.route('/gui/<path:path>')
  34. def send_img(path):
  35. return send_from_directory('interface/UserData', path)
  36. if __name__ == '__main__':
  37. socketio.run(app,port=4000,debug=True)