-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimezones.py
89 lines (67 loc) · 2.78 KB
/
timezones.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
from flask_restx import Namespace, Resource, reqparse, inputs
from pytz import timezone, common_timezones, country_timezones
#
from commonFunctions import *
#
timezonesNamespace = Namespace('timezones', description='Namespace to manipulate and get some informations about timezones...')
#
parser_timezones_infos = reqparse.RequestParser()
parser_timezones_infos.add_argument('timezone', type=str, required=True, choices=getAllTimezones(), help='Select here the IANA (Internet Assigned Numbers Authority) timezone...')
parser_timezones_infos.add_argument('all_cdn', type=inputs.boolean, required=False, default=False, help='Do you want to include all country flags cdn\'s ?')
#
@timezonesNamespace.route('')
@timezonesNamespace.expect(parser_timezones_infos)
class TimezonesInfos(Resource):
#
def get(self):
"""
Get all informations about the wished timezone...
"""
#
args = parser_timezones_infos.parse_args()
#
now_utc = datetime.now(timezone('UTC'))
#
country = getCountry(args["timezone"], bool(args["all_cdn"]))
#
return {
"timezone": {
"name": args["timezone"],
"UTC offset": now_utc.astimezone(timezone(args["timezone"])).strftime("%z"),
"date_and_time": now_utc.strftime("%Y-%m-%d %H:%M:%S")
},
"country": country,
}, 200
#
parser_timezones_by_country = reqparse.RequestParser()
#
parser_timezones_by_country.add_argument('country', type=str, required=True, choices=getAllCountries(), help='Select here the country...')
parser_timezones_by_country.add_argument('all_cdn', type=inputs.boolean, required=False, default=False, help='Do you want to include all country flags cdn\'s ?')
parser_timezones_by_country.add_argument('all_infos', type=inputs.boolean, required=False, default=False, help='Do you want all informations about timezones ?')
#
@timezonesNamespace.route('/byCountry')
@timezonesNamespace.expect(parser_timezones_by_country)
class TimezonesByCountries(Resource):
#
def get(self):
"""
Get all timezones (with all informations) for a selected country...
"""
#
args = parser_timezones_by_country.parse_args()
#
all_timezones_by_country = getAllTimezonesByCountry(args["country"], args["all_infos"])
#
if args["all_infos"]:
#
country = getCountry(list(all_timezones_by_country.keys())[0], args["all_cdn"])
#
else:
#
country = getCountry(all_timezones_by_country[0], args["all_cdn"])
#
return {
"country": country,
"timezones": all_timezones_by_country
}, 200