Sentry Log

mail@pastecode.io avatar
unknown
python
2 years ago
1.4 kB
5
Indexable
Never
import os, sys, ftplib
import pytz
import logging
from datetime import datetime, timedelta
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
print(os.path.abspath(BASE_DIR))
sys.path.insert(0, os.path.abspath(BASE_DIR))
import setting
import sentry_sdk
sentry_sdk.init({
    "dsn": 'https://df82d412e13047e8a873aae00de6f1f6@o1009180.ingest.sentry.io/5973196'
})
tz_tokyo = pytz.timezone('Asia/Tokyo')
def check_file_in_table_checklist():
    logging.info('Start check file receive')
    cur = setting.connection_middle()
    start_date = (datetime.now(tz=tz_tokyo) - timedelta(minutes=60)).strftime('%Y-%m-%d %H:%M:%S')
    end_date = (datetime.now(tz=tz_tokyo)).strftime('%Y-%m-%d %H:%M:%S')
    print(start_date)
    sql = """SELECT filename, receive_status, filename_with_suffix
            FROM kasumi_integration_checklist
            WHERE expected_to_receive_date >= %s AND expected_to_receive_date <= %s;"""
    params = (start_date, end_date,)
    cur.execute(sql, params)
    result = cur.fetchall()
    files_checklist = []
    files_ftp = setting.ftp_inbound_connect()
    if len(result) > 0:
        for res in result:
            if not res[1]:
                files_checklist.append(res[0])
    if len(files_checklist) > 0:
        raise Exception('File(s) not received : ' + str(files_checklist))
check_file_in_table_checklist()