├── Procfile ├── .gitignore ├── requirements.txt ├── templates └── index.html ├── main.py └── helpers.py /Procfile: -------------------------------------------------------------------------------- 1 | worker: gunicorn main:app -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | venv/* 2 | __pycache__/* -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | pytz 3 | gunicorn -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 |

Hello world!

3 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, render_template 2 | 3 | from helpers import get_date_and_time 4 | 5 | app = Flask(__name__, template_folder="templates") 6 | 7 | 8 | @app.route("/") 9 | def homepage(): 10 | return render_template("index.html") 11 | 12 | 13 | @app.route("/data") 14 | def data(): 15 | timezone = request.args.get("timezone") 16 | return ( 17 | get_date_and_time(timezone=timezone) 18 | if timezone 19 | else {"ok": "error", "error": "No timezone provided"} 20 | ) 21 | -------------------------------------------------------------------------------- /helpers.py: -------------------------------------------------------------------------------- 1 | import pytz 2 | from datetime import datetime 3 | 4 | 5 | def get_date_and_time(timezone): 6 | try: 7 | tz = pytz.timezone(timezone) 8 | except pytz.exceptions.UnknownTimeZoneError: 9 | timezones = pytz.all_timezones 10 | return { 11 | "ok": "error", 12 | "error": "Unknown timezone", 13 | "available_timezones": timezones, 14 | } 15 | data = datetime.now(tz) 16 | date = data.strftime("%d-%m-%Y") 17 | time = data.strftime("%H:%M:%S") 18 | return {"ok": "true", "date": date, "time": time} 19 | 20 | 21 | get_date_and_time("asia/kolkata") 22 | --------------------------------------------------------------------------------