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.

53 lines
1.3 KiB

  1. from flask import Flask, request
  2. from flask_restful import Resource, Api, abort
  3. import json
  4. import os
  5. app = Flask(__name__)
  6. api = Api(app)
  7. db_path = os.path.join(app.root_path, 'databases', 'users.json')
  8. with open(db_path, 'r') as f:
  9. users = json.load(f)
  10. class Alert(Resource):
  11. def post(self):
  12. args = request.form
  13. username= ""
  14. for user in users:
  15. if users[user]["id"] == args["id"]:
  16. username=user
  17. break
  18. trust = int(users[username]["trustability"])
  19. if trust > 20 or args["accepted"] == "true":
  20. return {"success":True}
  21. else:
  22. return {"success":False,"penalty":"{}".format(100*(20-trust))}
  23. class Denounce(Resource):
  24. def post(self):
  25. args = request.form
  26. reporter = args['id']
  27. denunciation_info = args['info']
  28. denunciation_priority = args['priority']
  29. denunciation_location = {
  30. "latitude": args['latitude'],
  31. "longitude": args['longitude']
  32. }
  33. denunciation = {
  34. 'reporter': reporter,
  35. 'info': denunciation_info,
  36. 'priority': denunciation_priority,
  37. 'location': denunciation_location
  38. }
  39. denunciations.append(denunciation)
  40. with open(db_path, 'w') as f:
  41. json.dump(denunciations, f, indent=4)
  42. return denunciation