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.

28 lines
713 B

6 years ago
  1. import os
  2. import copy
  3. import json
  4. from api.modules import utils
  5. from flask import Flask, request
  6. from flask_restful import Resource, Api, abort
  7. app = Flask(__name__)
  8. api = Api(app)
  9. db_path = os.path.join(app.root_path, 'databases', 'users.json')
  10. with open(db_path, 'r') as f:
  11. users = json.load(f)
  12. class Resources(Resource):
  13. def post(self):
  14. user = utils.find_by_id(users.values(), request.form['user_id'])
  15. return {
  16. 'daily_electricity_usage': user['daily_electricity_usage'],
  17. 'daily_water_usage': user['daily_water_usage']
  18. }
  19. if __name__ == '__main__':
  20. api.add_resource(Resources, '/resources', '/resources/')
  21. app.run(host='0.0.0.0', port=5000)