diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 03:01:41 +0100 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 03:01:41 +0100 |
commit | d0704be9edb02f9a70403c4fb298d3750e487ba3 (patch) | |
tree | f188dc82effe1ccb4452697e318be4c57543e134 /server |
Flask server and endpoints
Diffstat (limited to 'server')
-rw-r--r-- | server/.gitignore | 3 | ||||
-rw-r--r-- | server/requirements.txt | 9 | ||||
-rw-r--r-- | server/server.py | 28 |
3 files changed, 40 insertions, 0 deletions
diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..ee18991 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,3 @@ +venv/ +*.pyc +__pycache__/ diff --git a/server/requirements.txt b/server/requirements.txt new file mode 100644 index 0000000..80ea565 --- /dev/null +++ b/server/requirements.txt @@ -0,0 +1,9 @@ +click==7.1.2 +Flask==1.1.2 +Flask-Cors==3.0.8 +itsdangerous==1.1.0 +Jinja2==2.11.2 +MarkupSafe==1.1.1 +pytz==2020.1 +six==1.15.0 +Werkzeug==1.0.1 diff --git a/server/server.py b/server/server.py new file mode 100644 index 0000000..f1ddaa9 --- /dev/null +++ b/server/server.py @@ -0,0 +1,28 @@ +from datetime import datetime +from flask import abort, Flask, jsonify +from flask_cors import CORS +from pytz import common_timezones, timezone + + +app = Flask(__name__) +CORS(app) + + +@app.route('/zones/', methods=['GET']) +def zones(): + """ Return a list of common timezones """ + return jsonify(common_timezones) + + +@app.route('/time-at/<path:zone>', methods=['GET']) +def time_at(zone): + """ Return current time at given timezone """ + if zone not in common_timezones: + abort(404) + + tzobj = timezone(zone) + + return jsonify({ + 'zone': tzobj.zone, + 'time': datetime.now(tzobj).strftime('%a %d %b %Y %H:%M:%S'), + }) |