add read mail progress
This commit is contained in:
@@ -16,6 +16,9 @@ def main():
|
|||||||
# initialize discord
|
# initialize discord
|
||||||
print("init discord done")
|
print("init discord done")
|
||||||
_accepted_appointments = read_mails_and_find_confirmation_contacts(mode='default')
|
_accepted_appointments = read_mails_and_find_confirmation_contacts(mode='default')
|
||||||
|
print(f"找到 {len(_accepted_appointments)} 个已确认预约")
|
||||||
|
for appointment in _accepted_appointments:
|
||||||
|
print(create_message_from_item(appointment))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -246,39 +246,56 @@ def find_confirmation_contacts_mail_list(mail_list, subjects: list = None):
|
|||||||
mails_messages = []
|
mails_messages = []
|
||||||
gmx_proxy_config = get_gmx_proxy_config()
|
gmx_proxy_config = get_gmx_proxy_config()
|
||||||
yahoo_proxy_config = get_yahoo_proxy_config()
|
yahoo_proxy_config = get_yahoo_proxy_config()
|
||||||
|
|
||||||
grouped_mails = group_mails_by_provider(mail_list)
|
grouped_mails = group_mails_by_provider(mail_list)
|
||||||
|
total_mails = len(mail_list)
|
||||||
|
completed_count = 0
|
||||||
|
|
||||||
|
print(f"共需读取 {total_mails} 个邮箱,分为 {len(grouped_mails)} 个供应商组")
|
||||||
|
|
||||||
for provider_key, provider_mail_list in grouped_mails.items():
|
for provider_key, provider_mail_list in grouped_mails.items():
|
||||||
strategy = get_strategy(provider_key) if provider_key in ["gmail", "yahoo", "gmx", "outlook", "163", "rambler", "naver", "onet", "web_de", "inbox_lv", "sina", "pissmail", "default"] else get_strategy(provider_mail_list[0].mail)
|
strategy = get_strategy(provider_mail_list[0].mail)
|
||||||
print(f"[{strategy.name}] 处理 {len(provider_mail_list)} 个邮箱 (max_workers={strategy.max_workers})")
|
provider_total = len(provider_mail_list)
|
||||||
|
provider_completed = 0
|
||||||
|
print(f"[{strategy.name}] 开始处理 {provider_total} 个邮箱 (max_workers={strategy.max_workers})")
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers=strategy.max_workers) as executor:
|
with ThreadPoolExecutor(max_workers=strategy.max_workers) as executor:
|
||||||
futures = []
|
futures = {}
|
||||||
processed = 0
|
processed = 0
|
||||||
|
|
||||||
for mail in provider_mail_list:
|
for mail in provider_mail_list:
|
||||||
proxy_config = None
|
proxy_config = None
|
||||||
if is_gmx_address(mail.mail) and gmx_proxy_config is not None:
|
if is_gmx_address(mail.mail) and gmx_proxy_config is not None:
|
||||||
proxy_config = gmx_proxy_config
|
proxy_config = gmx_proxy_config
|
||||||
elif is_yahoo_address(mail.mail) and yahoo_proxy_config is not None:
|
elif is_yahoo_address(mail.mail) and yahoo_proxy_config is not None:
|
||||||
proxy_config = yahoo_proxy_config
|
proxy_config = yahoo_proxy_config
|
||||||
|
|
||||||
future = executor.submit(
|
future = executor.submit(
|
||||||
read_mail_with_strategy, mail, mails_messages, strategy, proxy_config, subjects
|
read_mail_with_strategy, mail, mails_messages, strategy, proxy_config, subjects
|
||||||
)
|
)
|
||||||
futures.append(future)
|
futures[future] = mail.mail
|
||||||
processed += 1
|
processed += 1
|
||||||
|
|
||||||
if strategy.should_wait_after_batch(processed):
|
if strategy.should_wait_after_batch(processed):
|
||||||
time.sleep(strategy.batch_delay)
|
time.sleep(strategy.batch_delay)
|
||||||
processed = 0
|
processed = 0
|
||||||
|
|
||||||
for future in futures:
|
for future in futures:
|
||||||
try:
|
try:
|
||||||
future.result(timeout=strategy.timeout)
|
future.result(timeout=strategy.timeout)
|
||||||
|
provider_completed += 1
|
||||||
|
completed_count += 1
|
||||||
|
mail_addr = futures[future]
|
||||||
|
print(f"[{strategy.name}] 进度: {provider_completed}/{provider_total} | 总进度: {completed_count}/{total_mails} | 完成: {mail_addr}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"读取邮箱出错: {e}")
|
provider_completed += 1
|
||||||
|
completed_count += 1
|
||||||
|
mail_addr = futures[future]
|
||||||
|
print(f"[{strategy.name}] 进度: {provider_completed}/{provider_total} | 总进度: {completed_count}/{total_mails} | 错误: {mail_addr} - {e}")
|
||||||
|
|
||||||
|
print(f"[{strategy.name}] 完成处理 {provider_total} 个邮箱")
|
||||||
|
|
||||||
|
print(f"全部邮箱读取完成,共读取 {len(mails_messages)} 封邮件")
|
||||||
|
|
||||||
accepted_appointment_list = []
|
accepted_appointment_list = []
|
||||||
if len(mails_messages) > 0:
|
if len(mails_messages) > 0:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ DOMAIN_ALICE_IT = "alice.it"
|
|||||||
DOMAIN_MARS_DTI_NE_JP = "mars.dti.ne.jp"
|
DOMAIN_MARS_DTI_NE_JP = "mars.dti.ne.jp"
|
||||||
DOMAN_BTVM_NE_JP = "btvm.ne.jp"
|
DOMAN_BTVM_NE_JP = "btvm.ne.jp"
|
||||||
DOMAN_AURORA_DTI_NE_JP = "aurora.dti.ne.jp"
|
DOMAN_AURORA_DTI_NE_JP = "aurora.dti.ne.jp"
|
||||||
DOMAN_GMAIL = "gmail.com"
|
DOMAIN_GMAIL = "gmail.com"
|
||||||
DOMAIN_GMX = "gmx.com"
|
DOMAIN_GMX = "gmx.com"
|
||||||
DOMAIN_GMX_NET = "gmx.net"
|
DOMAIN_GMX_NET = "gmx.net"
|
||||||
DOMAIN_GMX_AT = "gmx.at"
|
DOMAIN_GMX_AT = "gmx.at"
|
||||||
@@ -125,7 +125,7 @@ def create_imap(login: str):
|
|||||||
elif DOMAN_BTVM_NE_JP in login:
|
elif DOMAN_BTVM_NE_JP in login:
|
||||||
# imap = imaplib.IMAP4_SSL(BTVM_NE_JP)
|
# imap = imaplib.IMAP4_SSL(BTVM_NE_JP)
|
||||||
imap = IMAPClient(BTVM_NE_JP, use_uid=True)
|
imap = IMAPClient(BTVM_NE_JP, use_uid=True)
|
||||||
elif DOMAN_GMAIL in login:
|
elif DOMAIN_GMAIL in login:
|
||||||
# imap = imaplib.IMAP4_SSL(SEREVER_GMAIL, port=993)
|
# imap = imaplib.IMAP4_SSL(SEREVER_GMAIL, port=993)
|
||||||
imap = IMAPClient(SEREVER_GMAIL, use_uid=True)
|
imap = IMAPClient(SEREVER_GMAIL, use_uid=True)
|
||||||
elif DOMAIN_ONET in login:
|
elif DOMAIN_ONET in login:
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class ProviderStrategy:
|
|||||||
每批次之间的延迟(秒)
|
每批次之间的延迟(秒)
|
||||||
"""
|
"""
|
||||||
name: str = "default"
|
name: str = "default"
|
||||||
max_workers: int = 10
|
max_workers: int = 80
|
||||||
min_delay: float = 1.0
|
min_delay: float = 1.0
|
||||||
max_delay: float = 3.0
|
max_delay: float = 3.0
|
||||||
max_retries: int = 3
|
max_retries: int = 3
|
||||||
|
|||||||
Reference in New Issue
Block a user