employee_attendance.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from flask import Flask, request, Response, jsonify, send_file
  2. from data_employee import DataEmployee
  3. from xlsx_creator import xlsx_creator
  4. import json
  5. app = Flask(__name__)
  6. @app.after_request
  7. def after_request(response):
  8. response.headers.add('Access-Control-Allow-Origin', '*')
  9. response.headers.add('Access-Control-Allow-Headers',
  10. 'Content-Type,Authorization')
  11. response.headers.add('Access-Control-Allow-Methods',
  12. 'GET,PUT,POST,DELETE,OPTIONS')
  13. return response
  14. @app.route('/get_data', methods=['POST'])
  15. def get_data():
  16. FIOS = request.values['fios'].split(',')
  17. STARTDATE = request.values['startDate']
  18. ENDDATE = request.values['endDate']
  19. DATA = DataEmployee(FIOS, STARTDATE, ENDDATE)
  20. return jsonify(DATA.get_json())
  21. @app.route('/get_xlsx_file', methods=['POST'])
  22. def get_xlsx_file():
  23. xlsx = xlsx_creator(json.loads(request.data))
  24. return send_file(xlsx.cook_xlsx(), as_attachment=xlsx.FileName)
  25. if __name__ == "__main__":
  26. app.run(host='0.0.0.0')