update: saving file upon exit

This commit is contained in:
2026-06-04 15:18:53 +08:00
parent b4afb01dfa
commit a4d47d8b85
3 changed files with 26 additions and 13 deletions
+17 -7
View File
@@ -46,9 +46,9 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
class Status(Enum):
IDLE = 0
READY = 1
RUNNING = 3
STANDBY = 4
CLOSING = 5
RUNNING = 2
STANDBY = 3
CLOSING = 4
class ColumnMapping:
def __init__(self, email=None, recipient=None, code=None, region=None, sent=None, variables=None):
@@ -337,6 +337,17 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
sp.set('merge', merge)
sp.set('progress', lambda: progress)
def save():
try:
file = Path('.').joinpath(filename or f'Mailer-{datetime.now().strftime('%Y%m%d-%H%M%S-%f')}.xlsx').resolve()
logger.info('Saving file at %s', str(file))
wb.save(file)
except Exception as e:
logger.error('Error while writing data to file', exc_info=e)
exit = sp.pop('exit')
sp.set('exit', lambda: (save() if options.get('writable') and status.value >= 2 else None, exit()))
class MismatchedEmailSubject(Exception): pass
class MismatchedEmailAddress(Exception): pass
@@ -553,7 +564,7 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
status = Status.STANDBY
continue
if options.get('save'):
if options.get('writable'):
try:
status = Status.CLOSING
flow.allow(Wait, False)
@@ -565,9 +576,8 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
except Close:
pass
except Exception as e:
file = Path('.').joinpath(filename or f'Mailer-{datetime.now().strftime('%Y%m%d-%H%M%S-%f')}.xlsx').resolve()
logger.warning('RPC communication failed; saving at %s', str(file), exc_info=e)
wb.save(file)
logger.warning('RPC communication failed', exc_info=e)
save()
flow.allow(Timeout, False)
flow.allow(Close, False)