update: printing out max_occurrence and retry, etc.
This commit is contained in:
19
邮件批量发送.py
19
邮件批量发送.py
@@ -27,7 +27,7 @@ parser.add_argument('-a', '--address', type=str, nargs='?', default='')
|
|||||||
parser.add_argument('-p', '--password', type=str, nargs='?', default='')
|
parser.add_argument('-p', '--password', type=str, nargs='?', default='')
|
||||||
parser.add_argument('-t', '--timeout', type=int, nargs='?', default=60)
|
parser.add_argument('-t', '--timeout', type=int, nargs='?', default=60)
|
||||||
parser.add_argument('-i', '--interval', type=int, nargs='?', default=10)
|
parser.add_argument('-i', '--interval', type=int, nargs='?', default=10)
|
||||||
parser.add_argument('-m', '--max-occurrence', type=int, nargs='?', default=5)
|
parser.add_argument('-m', '--max-occurrence', type=int, nargs='?', default=0)
|
||||||
parser.add_argument('-T', '--timezone', type=str, nargs='?', default='')
|
parser.add_argument('-T', '--timezone', type=str, nargs='?', default='')
|
||||||
parser.add_argument('-r', '--retry', type=int, nargs='?', default=3)
|
parser.add_argument('-r', '--retry', type=int, nargs='?', default=3)
|
||||||
|
|
||||||
@@ -184,6 +184,7 @@ def main():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
print(f'[信息] 正在打开草稿邮件')
|
||||||
# 打开草稿箱
|
# 打开草稿箱
|
||||||
click("li[data-id='default0/Brouillons']", condition=EC.presence_of_element_located)
|
click("li[data-id='default0/Brouillons']", condition=EC.presence_of_element_located)
|
||||||
click("button[data-id='default0/Brouillons']", condition=EC.presence_of_element_located)
|
click("button[data-id='default0/Brouillons']", condition=EC.presence_of_element_located)
|
||||||
@@ -222,23 +223,26 @@ def main():
|
|||||||
codes = data.get(args.column_code, [None] * limit)
|
codes = data.get(args.column_code, [None] * limit)
|
||||||
sents = data.setdefault(args.column_sent, [None] * limit)
|
sents = data.setdefault(args.column_sent, [None] * limit)
|
||||||
|
|
||||||
print(f'[信息] 已读取联系人信息共 {limit} 条')
|
|
||||||
if limit == 0: continue
|
|
||||||
|
|
||||||
rate = 60 / (args.interval + 3)
|
rate = 60 / (args.interval + 3)
|
||||||
length = list.count(sents, None)
|
length = list.count(sents, None)
|
||||||
timezone = ZoneInfo(args.timezone) if args.timezone else None
|
timezone = ZoneInfo(args.timezone) if args.timezone else None
|
||||||
|
|
||||||
|
print(f'[信息] 已读取联系人信息共 {limit} 条')
|
||||||
|
print(f'[信息] 预计发送数量 {length}')
|
||||||
|
|
||||||
print(f'[信息] 当前发送速率 {round(rate, 2)} 封/分钟')
|
print(f'[信息] 当前发送速率 {round(rate, 2)} 封/分钟')
|
||||||
if rate > 8.33: print('[警告] 当前发送速率已超出限制 8.33 封/分钟')
|
if rate > 8.33: print('[警告] 当前发送速率已超出限制 8.33 封/分钟')
|
||||||
|
|
||||||
print(f'[信息] 预计使用时间 {timedelta(minutes=length / rate)}')
|
print(f'[信息] 预计使用时间 {timedelta(minutes=length / rate)}')
|
||||||
|
print(f'[信息] 已设定允许重试次数:{args.retry}')
|
||||||
|
print(f'[信息] 已设定最大重复次数:{args.max_occurrence or '无'}')
|
||||||
print(f'[信息] 当前时区:{timezone or '无'}')
|
print(f'[信息] 当前时区:{timezone or '无'}')
|
||||||
|
|
||||||
entries = list(filter(lambda it: it.get('locale') == suffix, greetings))
|
entries = list(filter(lambda it: it.get('locale') == suffix, greetings))
|
||||||
locale = dict(entries[0]) if len(entries) > 0 else None
|
locale = dict(entries[0]) if len(entries) > 0 else None
|
||||||
print(f'[信息] 当前语言:{str(suffix).upper() if locale else '无'}')
|
print(f'[信息] 当前语言:{str(suffix).upper() if locale else '无'}')
|
||||||
|
|
||||||
if input('[????] 是否继续?确定 (y) / 取消 (N): ') not in ['Y', 'y']:
|
if input('[????] 开始发送?确定 (y) / 取消 (N): ') not in ['Y', 'y']:
|
||||||
print('[信息] 操作取消')
|
print('[信息] 操作取消')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -297,7 +301,7 @@ def main():
|
|||||||
subject = target
|
subject = target
|
||||||
print(f'[信息] 已更新邮件主题设定')
|
print(f'[信息] 已更新邮件主题设定')
|
||||||
else:
|
else:
|
||||||
raise Exception('操作取消')
|
raise Exception('邮件主题意外变更')
|
||||||
|
|
||||||
ready(driver, lambda x: x.find_element(By.CSS_SELECTOR, ".io-ox-busy"))
|
ready(driver, lambda x: x.find_element(By.CSS_SELECTOR, ".io-ox-busy"))
|
||||||
locate("div.io-ox-mail-compose-window iframe", condition=EC.frame_to_be_available_and_switch_to_it)
|
locate("div.io-ox-mail-compose-window iframe", condition=EC.frame_to_be_available_and_switch_to_it)
|
||||||
@@ -365,7 +369,8 @@ def main():
|
|||||||
click("button[data-action='close']", parent=mails[0])
|
click("button[data-action='close']", parent=mails[0])
|
||||||
# 删除过期邮件
|
# 删除过期邮件
|
||||||
click("div.modal-footer button[data-action='delete']")
|
click("div.modal-footer button[data-action='delete']")
|
||||||
except:
|
except Exception as e:
|
||||||
|
print(f"[警告] 关闭邮件时发生了 '{type(e)}' 异常")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if attempt < args.retry:
|
if attempt < args.retry:
|
||||||
|
|||||||
Reference in New Issue
Block a user