@@ 20-94 (lines=75) @@ | ||
17 | def on_options(req, resp): |
|
18 | resp.status = falcon.HTTP_200 |
|
19 | ||
20 | @staticmethod |
|
21 | def on_get(req, resp): |
|
22 | admin_control(req) |
|
23 | print(req.params) |
|
24 | start_datetime_local = req.params.get('startdatetime') |
|
25 | end_datetime_local = req.params.get('enddatetime') |
|
26 | ||
27 | timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) |
|
28 | if config.utc_offset[0] == '-': |
|
29 | timezone_offset = -timezone_offset |
|
30 | ||
31 | if start_datetime_local is None: |
|
32 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
33 | description="API.INVALID_START_DATETIME_FORMAT") |
|
34 | else: |
|
35 | start_datetime_local = str.strip(start_datetime_local) |
|
36 | try: |
|
37 | start_datetime_utc = datetime.strptime(start_datetime_local, |
|
38 | '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ |
|
39 | timedelta(minutes=timezone_offset) |
|
40 | except ValueError: |
|
41 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
42 | description="API.INVALID_START_DATETIME_FORMAT") |
|
43 | ||
44 | if end_datetime_local is None: |
|
45 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
46 | description="API.INVALID_END_DATETIME_FORMAT") |
|
47 | else: |
|
48 | end_datetime_local = str.strip(end_datetime_local) |
|
49 | try: |
|
50 | end_datetime_utc = datetime.strptime(end_datetime_local, |
|
51 | '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ |
|
52 | timedelta(minutes=timezone_offset) |
|
53 | except ValueError: |
|
54 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
55 | description="API.INVALID_END_DATETIME_FORMAT") |
|
56 | ||
57 | if start_datetime_utc >= end_datetime_utc: |
|
58 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
59 | title='API.BAD_REQUEST', |
|
60 | description='API.START_DATETIME_MUST_BE_EARLIER_THAN_END_DATETIME') |
|
61 | ||
62 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
63 | cursor = cnx.cursor() |
|
64 | ||
65 | query = (" SELECT id, recipient_name, recipient_email, " |
|
66 | " subject, message, attachment_file_name, " |
|
67 | " created_datetime_utc, scheduled_datetime_utc, status " |
|
68 | " FROM tbl_email_messages " |
|
69 | " WHERE created_datetime_utc >= %s AND created_datetime_utc < %s " |
|
70 | " ORDER BY created_datetime_utc ") |
|
71 | cursor.execute(query, (start_datetime_utc, end_datetime_utc)) |
|
72 | rows = cursor.fetchall() |
|
73 | ||
74 | if cursor: |
|
75 | cursor.close() |
|
76 | if cnx: |
|
77 | cnx.close() |
|
78 | ||
79 | result = list() |
|
80 | if rows is not None and len(rows) > 0: |
|
81 | for row in rows: |
|
82 | meta_result = {"id": row[0], |
|
83 | "recipient_name": row[1], |
|
84 | "recipient_email": row[2], |
|
85 | "subject": row[3], |
|
86 | "message": row[4].replace("<br>", ""), |
|
87 | "attachment_file_name": row[5], |
|
88 | "created_datetime": row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, |
|
89 | "scheduled_datetime": |
|
90 | row[7].timestamp() * 1000 if isinstance(row[7], datetime) else None, |
|
91 | "status": row[8]} |
|
92 | result.append(meta_result) |
|
93 | ||
94 | resp.text = json.dumps(result) |
|
95 | ||
96 | @staticmethod |
|
97 | @user_logger |
@@ 20-94 (lines=75) @@ | ||
17 | def on_options(req, resp): |
|
18 | resp.status = falcon.HTTP_200 |
|
19 | ||
20 | @staticmethod |
|
21 | def on_get(req, resp): |
|
22 | admin_control(req) |
|
23 | ||
24 | start_datetime_local = req.params.get('startdatetime') |
|
25 | end_datetime_local = req.params.get('enddatetime') |
|
26 | ||
27 | timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) |
|
28 | if config.utc_offset[0] == '-': |
|
29 | timezone_offset = -timezone_offset |
|
30 | ||
31 | if start_datetime_local is None: |
|
32 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
33 | description="API.INVALID_START_DATETIME_FORMAT") |
|
34 | else: |
|
35 | start_datetime_local = str.strip(start_datetime_local) |
|
36 | try: |
|
37 | start_datetime_utc = datetime.strptime(start_datetime_local, |
|
38 | '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ |
|
39 | timedelta(minutes=timezone_offset) |
|
40 | except ValueError: |
|
41 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
42 | description="API.INVALID_START_DATETIME_FORMAT") |
|
43 | ||
44 | if end_datetime_local is None: |
|
45 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
46 | description="API.INVALID_END_DATETIME_FORMAT") |
|
47 | else: |
|
48 | end_datetime_local = str.strip(end_datetime_local) |
|
49 | try: |
|
50 | end_datetime_utc = datetime.strptime(end_datetime_local, |
|
51 | '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ |
|
52 | timedelta(minutes=timezone_offset) |
|
53 | except ValueError: |
|
54 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
55 | description="API.INVALID_END_DATETIME_FORMAT") |
|
56 | ||
57 | if start_datetime_utc >= end_datetime_utc: |
|
58 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
59 | title='API.BAD_REQUEST', |
|
60 | description='API.START_DATETIME_MUST_BE_EARLIER_THAN_END_DATETIME') |
|
61 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
62 | cursor = cnx.cursor() |
|
63 | ||
64 | query = (" SELECT id, recipient_name, recipient_openid, message_template_id, " |
|
65 | " message_data, created_datetime_utc, scheduled_datetime_utc, " |
|
66 | " acknowledge_code, status " |
|
67 | " FROM tbl_wechat_messages_outbox " |
|
68 | " WHERE created_datetime_utc >= %s AND created_datetime_utc < %s " |
|
69 | " ORDER BY created_datetime_utc DESC ") |
|
70 | cursor.execute(query, (start_datetime_utc, end_datetime_utc)) |
|
71 | rows = cursor.fetchall() |
|
72 | ||
73 | if cursor: |
|
74 | cursor.close() |
|
75 | if cnx: |
|
76 | cnx.close() |
|
77 | ||
78 | result = list() |
|
79 | if rows is not None and len(rows) > 0: |
|
80 | for row in rows: |
|
81 | meta_result = {"id": row[0], |
|
82 | "recipient_name": row[1], |
|
83 | "recipient_openid": row[2], |
|
84 | "message_template_id": row[3], |
|
85 | "message_data": row[4], |
|
86 | "created_datetime_utc": |
|
87 | row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, |
|
88 | "scheduled_datetime_utc": |
|
89 | row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, |
|
90 | "acknowledge_code": row[7], |
|
91 | "status": row[8]} |
|
92 | result.append(meta_result) |
|
93 | ||
94 | resp.text = json.dumps(result) |
|
95 | ||
96 | @staticmethod |
|
97 | @user_logger |
@@ 1128-1200 (lines=73) @@ | ||
1125 | def on_options(req, resp): |
|
1126 | resp.status = falcon.HTTP_200 |
|
1127 | ||
1128 | @staticmethod |
|
1129 | def on_get(req, resp): |
|
1130 | admin_control(req) |
|
1131 | start_datetime_local = req.params.get('startdatetime') |
|
1132 | end_datetime_local = req.params.get('enddatetime') |
|
1133 | ||
1134 | timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) |
|
1135 | if config.utc_offset[0] == '-': |
|
1136 | timezone_offset = -timezone_offset |
|
1137 | ||
1138 | if start_datetime_local is None: |
|
1139 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1140 | description="API.INVALID_START_DATETIME_FORMAT") |
|
1141 | else: |
|
1142 | start_datetime_local = str.strip(start_datetime_local) |
|
1143 | try: |
|
1144 | start_datetime_utc = datetime.strptime(start_datetime_local, |
|
1145 | '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ |
|
1146 | timedelta(minutes=timezone_offset) |
|
1147 | except ValueError: |
|
1148 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1149 | description="API.INVALID_START_DATETIME_FORMAT") |
|
1150 | ||
1151 | if end_datetime_local is None: |
|
1152 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1153 | description="API.INVALID_END_DATETIME_FORMAT") |
|
1154 | else: |
|
1155 | end_datetime_local = str.strip(end_datetime_local) |
|
1156 | try: |
|
1157 | end_datetime_utc = datetime.strptime(end_datetime_local, |
|
1158 | '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \ |
|
1159 | timedelta(minutes=timezone_offset) |
|
1160 | except ValueError: |
|
1161 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1162 | description="API.INVALID_END_DATETIME_FORMAT") |
|
1163 | ||
1164 | if start_datetime_utc >= end_datetime_utc: |
|
1165 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
1166 | title='API.BAD_REQUEST', |
|
1167 | description='API.START_DATETIME_MUST_BE_EARLIER_THAN_END_DATETIME') |
|
1168 | ||
1169 | cnx = mysql.connector.connect(**config.myems_user_db) |
|
1170 | cursor = cnx.cursor() |
|
1171 | ||
1172 | query = (" SELECT id, recipient_name, recipient_email, " |
|
1173 | " subject, message, created_datetime_utc, " |
|
1174 | " scheduled_datetime_utc, status " |
|
1175 | " FROM tbl_email_messages " |
|
1176 | " WHERE created_datetime_utc >= %s AND created_datetime_utc < %s " |
|
1177 | " ORDER BY created_datetime_utc ") |
|
1178 | cursor.execute(query, (start_datetime_utc, end_datetime_utc)) |
|
1179 | rows = cursor.fetchall() |
|
1180 | ||
1181 | if cursor: |
|
1182 | cursor.close() |
|
1183 | if cnx: |
|
1184 | cnx.close() |
|
1185 | ||
1186 | result = list() |
|
1187 | if rows is not None and len(rows) > 0: |
|
1188 | for row in rows: |
|
1189 | meta_result = {"id": row[0], |
|
1190 | "recipient_name": row[1], |
|
1191 | "recipient_email": row[2], |
|
1192 | "subject": row[3], |
|
1193 | "message": row[4].replace("<br>", ""), |
|
1194 | "created_datetime": row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, |
|
1195 | "scheduled_datetime": |
|
1196 | row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, |
|
1197 | "status": row[7]} |
|
1198 | result.append(meta_result) |
|
1199 | ||
1200 | resp.text = json.dumps(result) |
|
1201 | ||
1202 | @staticmethod |
|
1203 | def on_post(req, resp): |