-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrentDateTime.py
118 lines (87 loc) · 4.11 KB
/
currentDateTime.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#
from flask_restx import Namespace, Resource, inputs
from datetime import datetime
from pytz import timezone
#
from commonFunctions import *
#
currentDateTimeNamespace = Namespace('currentDateTime', description='Namespace to manipulate and get some informations about dates and times...')
#
parser_current_date_and_time_by_timezone = parser_current_date_and_time_by_timezone_template.copy()
parser_current_date_and_time_by_timezone.add_argument('all_cdn', type=inputs.boolean, required=False, default=False, help='Do you want to include all country flags cdn\'s ?')
#
@currentDateTimeNamespace.route('')
@currentDateTimeNamespace.expect(parser_current_date_and_time_by_timezone)
class CurrentDateTimeByTimezone(Resource):
#
def get(self):
"""
Convert and return the current datetime in the wished timezone...
"""
#
args = parser_current_date_and_time_by_timezone.parse_args()
#
now_utc = datetime.now(timezone('UTC'))
#
now_from_timezone = now_utc.astimezone(timezone(args["timezone"]))
#
date_time_template = args["datetime_format"]
#
country = getCountry(args["timezone"], args["all_cdn"])
#
return {
"date_and_time": now_from_timezone.strftime(date_time_template) if date_time_template is not None else now_from_timezone.timestamp(),
"format": date_time_template if date_time_template is not None else "UTC timestamp",
"timezone": {
"name": args["timezone"],
"UTC offset": now_from_timezone.astimezone(timezone(args["timezone"])).strftime("%z")
},
"country": country
}, 200
#
parser_current_date_and_time_by_timezone_for_conversion = parser_current_date_and_time_by_timezone_template.copy()
parser_current_date_and_time_by_timezone_for_conversion.add_argument('all_cdn', type=inputs.boolean, required=False, default=False, help='Do you want to include all country flags cdn\'s ?')
parser_current_date_and_time_by_timezone_for_conversion.add_argument('datetime', type=inputs.datetime_from_iso8601, default=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"), required=True, help='Wished date and time in the iso8601 format according to the UTC time zone')
#
@currentDateTimeNamespace.route('/conversion')
@currentDateTimeNamespace.expect(parser_current_date_and_time_by_timezone_for_conversion)
class CurrentDateTimeConversion(Resource):
#
def get(self):
"""
Convert and return the wished datetime specified in one particular format in the wished timezone...
"""
#
args = parser_current_date_and_time_by_timezone_for_conversion.parse_args()
#
#
now_from_timezone = args["datetime"].astimezone(timezone(args["timezone"]))
#
country = getCountry(args["timezone"], args["all_cdn"])
#
return {
"date_and_time": str(now_from_timezone),
"timezone": {
"name": args["timezone"],
"UTC offset": now_from_timezone.astimezone(timezone(args["timezone"])).strftime("%z")
},
"country": country
}, 200
#
parser_current_date_and_time_by_timezone_in_particular_calendar = parser_current_date_and_time_by_timezone_template.copy()
parser_current_date_and_time_by_timezone_in_particular_calendar.add_argument('datetime', type=inputs.datetime_from_iso8601, default=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"), required=True, help='Wished date and time in the iso8601 format according to the UTC time zone')
#
@currentDateTimeNamespace.route('/particularCalendar')
@currentDateTimeNamespace.expect(parser_current_date_and_time_by_timezone_in_particular_calendar)
class CurrentDateTimeByTimezoneInParticularCalendar(Resource):
#
def get(self):
#
return {"TODO": "TODO"}, 200
#
@currentDateTimeNamespace.route('/infos')
class CurrentDateTimeByTimezoneInfos(Resource):
#
def get(self):
#
return {"TODO": "TODO"}, 200