Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # app.py
- from datetime import datetime, timedelta
- from date_tools \
- import str_to_datetime, distance_between_dates
- from flask import Flask, request, render_template
- NAME_FOR_DATE_HTML_INPUT = "d"
- app = Flask(__name__)
- """
- manual calls:
- http://127.0.0.1:5555/distance?d=1970-08-01
- """
- @app.route("/distance", methods=['POST', 'GET'])
- def distance():
- bGET:bool = request.method == 'GET'
- bPOST:bool = request.method == 'POST'
- if(bPOST):
- the_user_date:str =\
- request.form[NAME_FOR_DATE_HTML_INPUT]
- else:
- if(bGET):
- the_user_date: str = \
- request.args[NAME_FOR_DATE_HTML_INPUT]
- # if
- # if-else
- the_date:datetime = str_to_datetime(
- the_user_date
- )
- diff:dict = distance_between_dates(
- the_date
- )
- """
- import json
- return json.dumps(diff)
- """
- return diff
- # def distance
- @app.route("/", methods=['POST', 'GET'])
- def respond_root():
- #return "<h1>The only service available is at /distance</h1>"
- return render_template(
- "input_date.html"
- )
- # def respond_root
- app.run(
- host="0.0.0.0",
- port=5555,
- debug=True
- )
Advertisement
Add Comment
Please, Sign In to add comment