am_dot_com

SW 2023-03-24

Mar 24th, 2023 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. # app.py
  2. from datetime import datetime, timedelta
  3.  
  4. from date_tools \
  5. import str_to_datetime, distance_between_dates
  6.  
  7. from flask import Flask, request, render_template
  8.  
  9. NAME_FOR_DATE_HTML_INPUT = "d"
  10.  
  11. app = Flask(__name__)
  12.  
  13. """
  14. manual calls:
  15. http://127.0.0.1:5555/distance?d=1970-08-01
  16. """
  17. @app.route("/distance", methods=['POST', 'GET'])
  18. def distance():
  19. bGET:bool = request.method == 'GET'
  20. bPOST:bool = request.method == 'POST'
  21.  
  22. if(bPOST):
  23. the_user_date:str =\
  24. request.form[NAME_FOR_DATE_HTML_INPUT]
  25. else:
  26. if(bGET):
  27. the_user_date: str = \
  28. request.args[NAME_FOR_DATE_HTML_INPUT]
  29. # if
  30. # if-else
  31.  
  32. the_date:datetime = str_to_datetime(
  33. the_user_date
  34. )
  35.  
  36. diff:dict = distance_between_dates(
  37. the_date
  38. )
  39.  
  40. """
  41. import json
  42. return json.dumps(diff)
  43. """
  44. return diff
  45. # def distance
  46.  
  47. @app.route("/", methods=['POST', 'GET'])
  48. def respond_root():
  49. #return "<h1>The only service available is at /distance</h1>"
  50. return render_template(
  51. "input_date.html"
  52. )
  53. # def respond_root
  54.  
  55. app.run(
  56. host="0.0.0.0",
  57. port=5555,
  58. debug=True
  59. )
Advertisement
Add Comment
Please, Sign In to add comment