diff --git a/check_results.py b/check_results.py index 80f0041..c29c89b 100644 --- a/check_results.py +++ b/check_results.py @@ -18,6 +18,7 @@ PENDING_SENTENCE = "Ce soir, entre 20:00 et 20:30, vous obtiendrez une réponse PENDING_SENTENCE_EN = "This evening between 20:00 and 20:30 you will receive a response by email." BLANK_URL = "about:blank" + class TlsPlaywright(threading.local): def __init__(self) -> None: self.playwright = sync_playwright().start() @@ -103,8 +104,7 @@ class ResultChecker: collection.document(reserve_pojo.id).update({u'accepted': status.name}) -# need to start at 21h00 -if __name__ == '__main__': +def check_results(): # get the list params.oracle_log_sender.send_log(msg="开始检查约会结果", subject=LOG_SUBJECT_EVENT, type=TYPE_EVENT_CHECK_RESULTS) db_manager = params.firebase_store_manager @@ -116,8 +116,7 @@ if __name__ == '__main__': reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict()) result_list.append(reserve_pojo) - - with ThreadPoolExecutor(max_workers=25) as executor: + with ThreadPoolExecutor(max_workers=15) as executor: for reserve in result_list: count = count + 1 if reserve.accepted is None or ResultEnum.ACCEPTED.value == reserve.accepted: @@ -126,3 +125,8 @@ if __name__ == '__main__': print("status is " + reserve.accepted) print(count) + + +# need to start at 21h00 +if __name__ == '__main__': + check_results() diff --git a/scheduler.py b/scheduler.py index 6f5aa09..9d36b36 100644 --- a/scheduler.py +++ b/scheduler.py @@ -1,6 +1,7 @@ from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor from apscheduler.schedulers.blocking import BlockingScheduler +from check_results import check_results from main import start_book from wait_for_sms import start_waiting_sms @@ -9,6 +10,10 @@ def waiting_for_sms_job(): start_waiting_sms(1, 32) +def check_results_job(): + check_results() + + def start_book_appointment(): start_book(1, 31) @@ -18,8 +23,19 @@ def start_waiting_sms_job(sched): # minute='30', # misfire_grace_time=10, # second='0', timezone='Europe/Paris', max_instances=1) - sched.add_job(waiting_for_sms_job, 'cron', day_of_week='mon-sat', hour='20', - minute='40', + sched.add_job(waiting_for_sms_job, 'cron', day_of_week='mon-sat', hour='21', + minute='15', + misfire_grace_time=10, + second='0', timezone='Europe/Paris', max_instances=1) + + +def start_check_results_job(sched): + # sched.add_job(start_book_appointment, 'cron', day_of_week='mon-sat', hour='10', + # minute='30', + # misfire_grace_time=10, + # second='0', timezone='Europe/Paris', max_instances=1) + sched.add_job(check_results(), 'cron', day_of_week='mon-sat', hour='21', + minute='15', misfire_grace_time=10, second='0', timezone='Europe/Paris', max_instances=1) @@ -30,7 +46,8 @@ def config_and_start_jobs(): 'processpool': ProcessPoolExecutor(12) } sched = BlockingScheduler(executors=executors) - start_waiting_sms_job(sched) + # start_waiting_sms_job(sched) + start_check_results_job(sched) sched.print_jobs() sched.start()