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.

83 lines
2.3 KiB

6 years ago
  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","crashes"]
  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 compaint_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. @socketio.on('check', namespace='/crashes_socket')
  46. def crash_handle(msg):
  47. change, data = file_check("crashes")
  48. if change:
  49. emit("new", data, namespace='/crashes_socket')
  50. @socketio.on('connect', namespace='/crashes_socket')
  51. def handle_crash():
  52. print("[INFO]: Received socket connection!")
  53. src = os.path.join(src_path, 'crashes.json')
  54. with open(src, 'r') as f:
  55. json_data = json.loads(f.read())
  56. emit("new", json.dumps(json_data), namespace="/crashes_socket")
  57. @app.route('/gui/<path:path>')
  58. def send_img(path):
  59. return send_from_directory('interface/UserData', path)
  60. if __name__ == '__main__':
  61. socketio.run(app,host="0.0.0.0",port=4000,debug=True)