minor fix
This commit is contained in:
46
main.py
46
main.py
@@ -10,7 +10,7 @@ import re
|
|||||||
import trio
|
import trio
|
||||||
import trio_websocket as ws
|
import trio_websocket as ws
|
||||||
|
|
||||||
from selenium.common.exceptions import StaleElementReferenceException, TimeoutException
|
from selenium.common.exceptions import StaleElementReferenceException, TimeoutException, InvalidSessionIdException
|
||||||
from selenium.webdriver import Chrome, ChromeOptions
|
from selenium.webdriver import Chrome, ChromeOptions
|
||||||
from selenium.webdriver.common.action_chains import ActionChains
|
from selenium.webdriver.common.action_chains import ActionChains
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
@@ -332,8 +332,6 @@ def main(driver: WebDriver):
|
|||||||
|
|
||||||
cursor = 0
|
cursor = 0
|
||||||
status = Status.ACTIVE
|
status = Status.ACTIVE
|
||||||
occurrences = {}
|
|
||||||
request = None
|
|
||||||
sent = 0
|
sent = 0
|
||||||
errors = 0
|
errors = 0
|
||||||
warnings = 0
|
warnings = 0
|
||||||
@@ -343,28 +341,27 @@ def main(driver: WebDriver):
|
|||||||
current = cursor
|
current = cursor
|
||||||
cursor += 1
|
cursor += 1
|
||||||
|
|
||||||
recipient = str(recipients[current]).strip()
|
|
||||||
name = names[current]
|
name = names[current]
|
||||||
code = codes[current]
|
code = codes[current]
|
||||||
axis = index[current]
|
axis = index[current]
|
||||||
|
|
||||||
occurrence = occurrences.setdefault(code, [0]) if code else [0]
|
occurrence = pandas.Series.count(frame[frame[cc] == code][cs]) if code is not None else 0
|
||||||
try: outbox.put(Command('setProgress', cursor, name, recipient, sent, warnings, errors))
|
recipient = str(recipients[current]).strip()
|
||||||
except ShutDown: break
|
|
||||||
|
|
||||||
if (remarks := frame.loc[axis, cs]) is not None and str(remarks).strip():
|
if (remarks := frame.loc[axis, cs]) is not None and str(remarks).strip():
|
||||||
tell(f'已跳过项目 {recipient}')
|
tell(f'已跳过项目 {recipient}')
|
||||||
occurrence[0] += 1
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (maximum := parameters.get('max_occurrence')) and occurrence[0] >= maximum:
|
if (maximum := parameters.get('max_occurrence')) and occurrence >= maximum:
|
||||||
tell(f'收件人 {recipient} 所属组织出现次数已超出限制 {occurrence}', level=1)
|
tell(f'已跳过项目 {recipient}')
|
||||||
warnings += 1
|
warnings += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
while status.isactive():
|
while status.isactive():
|
||||||
try:
|
try:
|
||||||
|
outbox.put(Command('setProgress', cursor, name, recipient, sent, warnings, errors, attempt))
|
||||||
tell('正在发送:%s (%.2f %%)' % (recipient, current / limit * 100))
|
tell('正在发送:%s (%.2f %%)' % (recipient, current / limit * 100))
|
||||||
|
|
||||||
clean = True
|
clean = True
|
||||||
attempt += 1
|
attempt += 1
|
||||||
request = get_request()
|
request = get_request()
|
||||||
@@ -457,7 +454,6 @@ def main(driver: WebDriver):
|
|||||||
click("div.io-ox-alert.io-ox-alert-error button[data-action='close']")
|
click("div.io-ox-alert.io-ox-alert-error button[data-action='close']")
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
frame.loc[axis, cs] = '✔️'
|
frame.loc[axis, cs] = '✔️'
|
||||||
occurrence[0] += 1
|
|
||||||
sent += 1
|
sent += 1
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -475,25 +471,37 @@ def main(driver: WebDriver):
|
|||||||
tell('已超出最大重试上限', level=1)
|
tell('已超出最大重试上限', level=1)
|
||||||
errors += 1
|
errors += 1
|
||||||
break
|
break
|
||||||
|
except (KeyboardInterrupt, InvalidSessionIdException, ShutDown):
|
||||||
|
request = None
|
||||||
|
exception = None
|
||||||
except Faillable as o:
|
except Faillable as o:
|
||||||
request = o.request
|
request = o.request
|
||||||
|
exception = None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
tell(f'发生错误 ({attempt})', e, level=0)
|
request = None
|
||||||
if connection.closed or isinstance(e, KeyboardInterrupt):
|
exception = e
|
||||||
status = Status.TERMINATED
|
|
||||||
break
|
if exception is not None:
|
||||||
|
try:
|
||||||
|
tell(f'发生错误 ({attempt})', exception, level=0)
|
||||||
outbox.put(Command('setStatus', 'FAILED'))
|
outbox.put(Command('setStatus', 'FAILED'))
|
||||||
request = inbox.get()
|
request = inbox.get()
|
||||||
|
except ShutDown:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if request == 'CANCEL':
|
||||||
|
outbox.put(Command('setStatus', 'CANCEL'))
|
||||||
|
status = Status.INACTIVE
|
||||||
|
break
|
||||||
if request == 'BYPASS':
|
if request == 'BYPASS':
|
||||||
outbox.put(Command('setStatus', 'BYPASS'))
|
outbox.put(Command('setStatus', 'BYPASS'))
|
||||||
break
|
break
|
||||||
if request == 'RESUME':
|
if request == 'RESUME':
|
||||||
outbox.put(Command('setStatus', 'RESUME'))
|
outbox.put(Command('setStatus', 'RESUME'))
|
||||||
continue
|
continue
|
||||||
if request == 'CANCEL':
|
|
||||||
outbox.put(Command('setStatus', 'CANCEL'))
|
tell('程序中断', level=1)
|
||||||
status = Status.INACTIVE
|
status = Status.TERMINATED
|
||||||
|
|
||||||
progress = cursor / limit * 100
|
progress = cursor / limit * 100
|
||||||
tell('当前进度:%.2f %%' % progress)
|
tell('当前进度:%.2f %%' % progress)
|
||||||
@@ -512,7 +520,7 @@ def main(driver: WebDriver):
|
|||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
tell(f'写入文件时发生错误 ({attempt})', e, level=1)
|
tell(f'写入文件时发生错误 ({attempt})', e, level=1)
|
||||||
time.sleep(1)
|
time.sleep(parameters.get('interval'))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if status.isalive(): outbox.put(Command('setStatus', 'FINISH'))
|
if status.isalive(): outbox.put(Command('setStatus', 'FINISH'))
|
||||||
|
|||||||
Reference in New Issue
Block a user