@@ 264-301 (lines=38) @@ | ||
261 | resp.status = falcon.HTTP_200 |
|
262 | _ = id_ |
|
263 | ||
264 | @staticmethod |
|
265 | def on_get(req, resp, id_): |
|
266 | admin_control(req) |
|
267 | if not id_.isdigit() or int(id_) <= 0: |
|
268 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
269 | description='API.INVALID_WECHAT_MESSAGE_ID') |
|
270 | ||
271 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
272 | cursor = cnx.cursor() |
|
273 | ||
274 | query = (" SELECT id, recipient_name, recipient_openid, message_template_id, " |
|
275 | " message_data, created_datetime_utc, scheduled_datetime_utc, " |
|
276 | " acknowledge_code, status " |
|
277 | " FROM tbl_wechat_messages_outbox " |
|
278 | " WHERE id = %s ") |
|
279 | cursor.execute(query, (id_,)) |
|
280 | row = cursor.fetchone() |
|
281 | ||
282 | if cursor: |
|
283 | cursor.close() |
|
284 | if cnx: |
|
285 | cnx.close() |
|
286 | ||
287 | if row is None: |
|
288 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
289 | description='API.WECHAT_MESSAGE_NOT_FOUND') |
|
290 | ||
291 | result = {"id": row[0], |
|
292 | "recipient_name": row[1], |
|
293 | "recipient_openid": row[2], |
|
294 | "recipient_template_id": row[3], |
|
295 | "message_data": row[4], |
|
296 | "created_datetime_utc": row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, |
|
297 | "scheduled_datetime_utc": row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, |
|
298 | "acknowledge_code": row[7], |
|
299 | "status": row[8]} |
|
300 | ||
301 | resp.text = json.dumps(result) |
|
302 | ||
303 | @staticmethod |
|
304 | @user_logger |
@@ 255-292 (lines=38) @@ | ||
252 | resp.status = falcon.HTTP_200 |
|
253 | _ = id_ |
|
254 | ||
255 | @staticmethod |
|
256 | def on_get(req, resp, id_): |
|
257 | admin_control(req) |
|
258 | if not id_.isdigit() or int(id_) <= 0: |
|
259 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
260 | description='API.INVALID_EMAIL_MESSAGE_ID') |
|
261 | ||
262 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
263 | cursor = cnx.cursor() |
|
264 | ||
265 | query = (" SELECT id, recipient_name, recipient_email, " |
|
266 | " subject, message, attachment_file_name, " |
|
267 | " created_datetime_utc, scheduled_datetime_utc, status " |
|
268 | " FROM tbl_email_messages " |
|
269 | " WHERE id = %s ") |
|
270 | cursor.execute(query, (id_,)) |
|
271 | row = cursor.fetchone() |
|
272 | ||
273 | if cursor: |
|
274 | cursor.close() |
|
275 | if cnx: |
|
276 | cnx.close() |
|
277 | ||
278 | if row is None: |
|
279 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
280 | description='API.EMAIL_MESSAGE_NOT_FOUND') |
|
281 | ||
282 | result = {"id": row[0], |
|
283 | "recipient_name": row[1], |
|
284 | "recipient_email": row[2], |
|
285 | "subject": row[3], |
|
286 | "message": row[4].replace("<br>", ""), |
|
287 | "attachment_file_name": row[5], |
|
288 | "created_datetime": row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, |
|
289 | "scheduled_datetime": row[7].timestamp() * 1000 if isinstance(row[7], datetime) else None, |
|
290 | "status": row[8]} |
|
291 | ||
292 | resp.text = json.dumps(result) |
|
293 | ||
294 | @staticmethod |
|
295 | @user_logger |
@@ 239-274 (lines=36) @@ | ||
236 | resp.status = falcon.HTTP_200 |
|
237 | _ = id_ |
|
238 | ||
239 | @staticmethod |
|
240 | def on_get(req, resp, id_): |
|
241 | admin_control(req) |
|
242 | if not id_.isdigit() or int(id_) <= 0: |
|
243 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
244 | description='API.INVALID_TEXT_MESSAGE_ID') |
|
245 | ||
246 | cnx = mysql.connector.connect(**config.myems_fdd_db) |
|
247 | cursor = cnx.cursor() |
|
248 | ||
249 | query = (" SELECT id, recipient_name, recipient_mobile, " |
|
250 | " message, created_datetime_utc, scheduled_datetime_utc, acknowledge_code, status " |
|
251 | " FROM tbl_text_messages_outbox " |
|
252 | " WHERE id = %s ") |
|
253 | cursor.execute(query, (id_,)) |
|
254 | row = cursor.fetchone() |
|
255 | ||
256 | if cursor: |
|
257 | cursor.close() |
|
258 | if cnx: |
|
259 | cnx.close() |
|
260 | ||
261 | if row is None: |
|
262 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
263 | description='API.TEXT_MESSAGE_NOT_FOUND') |
|
264 | ||
265 | result = {"id": row[0], |
|
266 | "recipient_name": row[1], |
|
267 | "recipient_mobile": row[2], |
|
268 | "message": row[3], |
|
269 | "created_datetime": row[4].timestamp() * 1000 if isinstance(row[4], datetime) else None, |
|
270 | "scheduled_datetime": row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, |
|
271 | "acknowledge_code": row[6], |
|
272 | "status": row[7]} |
|
273 | ||
274 | resp.text = json.dumps(result) |
|
275 | ||
276 | @staticmethod |
|
277 | @user_logger |
@@ 1366-1402 (lines=37) @@ | ||
1363 | resp.status = falcon.HTTP_200 |
|
1364 | _ = id_ |
|
1365 | ||
1366 | @staticmethod |
|
1367 | def on_get(req, resp, id_): |
|
1368 | admin_control(req) |
|
1369 | if not id_.isdigit() or int(id_) <= 0: |
|
1370 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1371 | description='API.INVALID_EMAIL_MESSAGE_ID') |
|
1372 | ||
1373 | cnx = mysql.connector.connect(**config.myems_user_db) |
|
1374 | cursor = cnx.cursor() |
|
1375 | ||
1376 | query = (" SELECT id, recipient_name, recipient_email, " |
|
1377 | " subject, message, created_datetime_utc, " |
|
1378 | " scheduled_datetime_utc, status " |
|
1379 | " FROM tbl_email_messages " |
|
1380 | " WHERE id = %s ") |
|
1381 | cursor.execute(query, (id_,)) |
|
1382 | row = cursor.fetchone() |
|
1383 | ||
1384 | if cursor: |
|
1385 | cursor.close() |
|
1386 | if cnx: |
|
1387 | cnx.close() |
|
1388 | ||
1389 | if row is None: |
|
1390 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1391 | description='API.EMAIL_MESSAGE_NOT_FOUND') |
|
1392 | ||
1393 | result = {"id": row[0], |
|
1394 | "recipient_name": row[1], |
|
1395 | "recipient_email": row[2], |
|
1396 | "subject": row[3], |
|
1397 | "message": row[4].replace("<br>", ""), |
|
1398 | "created_datetime": row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, |
|
1399 | "scheduled_datetime": row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, |
|
1400 | "status": row[7]} |
|
1401 | ||
1402 | resp.text = json.dumps(result) |
|
1403 | ||
1404 | @staticmethod |
|
1405 | @user_logger |