update: better name parsing

This commit is contained in:
2025-07-25 10:57:06 +08:00
parent 0f430b985f
commit 4195c56772

View File

@@ -14,7 +14,7 @@ from selenium.webdriver.remote.webelement import WebElement
from tkinter import Tk, filedialog from tkinter import Tk, filedialog
from datetime import datetime, timedelta from datetime import datetime, timedelta
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
from nameparser import HumanName, config from nameparser import HumanName
parser = argparse.ArgumentParser(description="邮件批量发送脚本") parser = argparse.ArgumentParser(description="邮件批量发送脚本")
parser.add_argument('input', nargs='?') parser.add_argument('input', nargs='?')
@@ -295,20 +295,17 @@ def main():
case hour if 12 <= hour < 18: registry = entry.get('registry')[1] case hour if 12 <= hour < 18: registry = entry.get('registry')[1]
case hour if 18 <= hour < 21: registry = entry.get('registry')[2] case hour if 18 <= hour < 21: registry = entry.get('registry')[2]
case _: registry = None case _: registry = None
clean = False
iframe = driver.switch_to.active_element iframe = driver.switch_to.active_element
action = ActionChains(driver) action = ActionChains(driver)
hello: str = registry or entry.get('default') clean = False
hello = registry or entry.get('default')
if name is not None and (name := str(name).strip()) and not contains_non_latin_alphabet(name): if name is not None and (name := str(name).strip()) and not contains_non_latin_alphabet(name):
const = config.CONSTANTS parts = HumanName(name)
const.titles.add('M.') parts.capitalize(force=True)
short = len(parts.first) < 3 or (len(parts.first) < 5 and parts.first.endswith('.'))
parts = HumanName(name, const) hello = ' '.join(filter(None, [hello, parts.title, parts.first, (parts.middle or parts.last) if short else None]))
parts.capitalize()
person = ' '.join(filter(None, [parts.title, parts.first or parts.middle or parts.last]))
hello = ' '.join([hello, person])
hello += ',' hello += ','
action.send_keys(hello).perform() action.send_keys(hello).perform()
@@ -338,7 +335,7 @@ def main():
alert = wait.until(lambda x: x.find_element(By.CSS_SELECTOR, "div.io-ox-alert.io-ox-alert-error")) alert = wait.until(lambda x: x.find_element(By.CSS_SELECTOR, "div.io-ox-alert.io-ox-alert-error"))
message = alert.text.replace('\n', ' ') message = alert.text.replace('\n', ' ')
if not message: print(f'[警告] 程序异常。请保持页面在前台显示,避免最小化') if not message: print(f'[警告] 程序异常。请保持页面在前台显示,避免遮挡或最小化')
else: print(f'[警告] ({attempt}): {message}') else: print(f'[警告] ({attempt}): {message}')
# 关闭警告 # 关闭警告