chore: remove verbose debug, keep only key path logging
This commit is contained in:
parent
dd72fb77d9
commit
fd41c6d6fe
@ -119,30 +119,22 @@ class TransferGateway(Gateway):
|
||||
return None
|
||||
|
||||
def get_transfer_data(self, mail):
|
||||
debug(f'get_transfer_data: from={mail.mailfrom} to={mail.mailto} expect_to={self.email}')
|
||||
if mail.mailfrom != '95555@message.cmbchina.com':
|
||||
debug(f'get_transfer_data: wrong sender')
|
||||
return None
|
||||
if mail.mailto != self.email:
|
||||
debug(f'get_transfer_data: mailto mismatch: {mail.mailto} != {self.email}')
|
||||
debug('get_transfer_data: mailto mismatch ' + str(mail.mailto) + ' != ' + self.email)
|
||||
return None
|
||||
if not mail.body.startswith('动账业务通知'):
|
||||
debug(f'get_transfer_data: body not start with 动账业务通知, head={mail.body[:30]}')
|
||||
return None
|
||||
ns = DictObject()
|
||||
match = re.search(r'交易金额\s*[::]\s*¥?\s*(\d+(?:\.\d+)?)', mail.body)
|
||||
if match:
|
||||
ns.amount = float(match.group(1))
|
||||
debug(f'get_transfer_data: amount={ns.amount}')
|
||||
match = re.search(r'摘要[::]\s*(\d{7})(?!\d)', mail.body)
|
||||
if match:
|
||||
ns.code = match.group(1)
|
||||
debug(f'get_transfer_data: code={ns.code}')
|
||||
if not hasattr(ns, 'amount'):
|
||||
debug(f'get_transfer_data: no amount found, body={mail.body[:200]}')
|
||||
return None
|
||||
if not hasattr(ns, 'code'):
|
||||
debug(f'get_transfer_data: no code found, body={mail.body[:200]}')
|
||||
if not hasattr(ns, 'amount') or not hasattr(ns, 'code'):
|
||||
debug('get_transfer_data: extract failed, amount=' + str(getattr(ns, 'amount', '?')) + ' code=' + str(getattr(ns, 'code', '?')))
|
||||
return None
|
||||
return ns
|
||||
|
||||
@ -269,34 +261,26 @@ class TransferGateway(Gateway):
|
||||
try:
|
||||
mail_date = parsedate_to_datetime(mail_date_str)
|
||||
if mail_date < cutoff:
|
||||
debug('mail[' + idx + '] date=' + str(mail_date_str) + ' older than 2 days, stop scanning')
|
||||
break # 从新到旧扫描,遇到旧邮件后面都更旧
|
||||
except Exception as de:
|
||||
debug('mail[' + idx + '] date parse error: ' + str(mail_date_str) + ' -> ' + str(de))
|
||||
debug('mail[' + idx + '] date older than 2 days, stop scanning')
|
||||
break
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
debug('mail[' + idx + '] no date header, skip')
|
||||
continue
|
||||
|
||||
from_addr = getattr(mail, 'mailfrom', '?')
|
||||
subject = getattr(mail, 'subject', '?')
|
||||
body_head = (getattr(mail, 'body', '') or '')[:50].replace('\n', ' ')
|
||||
debug('mail[' + idx + '] date=' + str(mail_date_str) + ' from=' + str(from_addr) + ' subj=' + str(subject) + ' body=' + body_head)
|
||||
|
||||
if from_addr != '95555@message.cmbchina.com':
|
||||
debug('mail[' + idx + '] EXIT: wrong sender')
|
||||
continue
|
||||
if not (getattr(mail, 'body', '') or '').startswith('动账业务通知'):
|
||||
debug('mail[' + idx + '] EXIT: not 动账业务通知')
|
||||
continue
|
||||
|
||||
data = self.get_transfer_data(mail)
|
||||
if data is None:
|
||||
debug('mail[' + idx + '] EXIT: get_transfer_data returned None')
|
||||
continue
|
||||
|
||||
code = str(data.code)
|
||||
amount = data.amount
|
||||
debug('mail[' + idx + '] code=' + code + ' amount=' + str(amount))
|
||||
debug('mail[' + idx + '] matched: code=' + code + ' amount=' + str(amount))
|
||||
|
||||
# 在transfercode表中查找 status=0 的记录并入账
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user