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.

66 lines
1.9 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. @socketio.on("check",namespace="/complaints_socket")
  34. def denunciation_handle(msg):
  35. change,data = file_check("complaints")
  36. if change:
  37. emit("new", data, namespace="/complaints_socket")
  38. @socketio.on('connect', namespace='/complaints_socket')
  39. def handle_my_custom_namespace_event():
  40. print("[INFO]: Received socket connection!")
  41. src = os.path.join(src_path,"complaints.json")
  42. with open(src,"r") as f:
  43. json_data = json.loads(f.read())
  44. emit("new", json.dumps(json_data), namespace="/complaints_socket")
  45. @app.route('/gui/<path:path>')
  46. def send_img(path):
  47. return send_from_directory('interface/UserData', path)
  48. if __name__ == '__main__':
  49. socketio.run(app,port=4000,debug=True)