blob: f1ddaa9f8379e7eff046d26f30d2c8ba29fb23ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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'),
})
|