From 13a17e3d79efd9f416c257a53a0d0e4a8b09cad2 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 24 Mar 2022 10:57:57 +0100 Subject: [PATCH] use listener instead of rabittmq --- commandor_page.py | 13 +++++-------- main.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/commandor_page.py b/commandor_page.py index 45f7573..d35064d 100644 --- a/commandor_page.py +++ b/commandor_page.py @@ -29,8 +29,9 @@ class CommandorPage: def __init__(self): self.otp_value = None - def _run(self, e: threading.Event, proxy, contact: ContactPojo, on_ready_for_otp): + def _run(self, e: threading.Event, proxy, contact: ContactPojo, on_ready_for_otp, on_success): self.contact = contact + self.on_success_listener = on_success with sync_playwright() as pwright: firefox_user_agents = filter(lambda user_agent: "firefox" in user_agent.lower(), user_agent_list) firefox_user_agents_list = list(firefox_user_agents) @@ -75,9 +76,9 @@ class CommandorPage: time.sleep(2) # check and send successful event - def start_page(self, proxy, contact: ContactPojo, on_ready_for_otp) -> threading.Event: + def start_page(self, proxy, contact: ContactPojo, on_ready_for_otp, on_sucess) -> threading.Event: e = threading.Event() - t = threading.Thread(target=self._run, args=(e, proxy, contact, on_ready_for_otp)) + t = threading.Thread(target=self._run, args=(e, proxy, contact, on_ready_for_otp, on_sucess)) t.start() return e @@ -137,11 +138,7 @@ class CommandorPage: firstName=contact.first_name, lastName=contact.last_name, email=contact.mail, passport=contact.passport, ccid=contact.ccid) result.id = id - channel = params.rabittmq_connection.channel() - # default exchange, for 'hello' queue - print("will publish message:" + result.to_json()) - channel.basic_publish(exchange='', routing_key=APPOINTMENT_QUEUE, - body=result.to_json()) + self.on_success_listener(result) def get_random_id_number_for_proxy() -> str: diff --git a/main.py b/main.py index eba90a9..eaf30c0 100644 --- a/main.py +++ b/main.py @@ -151,6 +151,18 @@ def on_message_received(ch, method, properties, body): is_finished = True +def on_success(result: ReserveResultPojo): + logger.info("on_success called.") + result.sim_position = current_sim_position + result.slot_position = current_card_pool_slot + logger.info(result) + firebase_store_manager.save(result) + oracle_log_sender.send_appoint_result(result) + # set the flag to True + global is_finished + is_finished = True + + def start_listen(): logger.info("start to listen to message queue") receiver = MessageReceiver() @@ -206,7 +218,7 @@ def start_book(): "password": params.PROXY_PASSWORD } commandor.start_page(proxy=proxy, contact=modem.contact, - on_ready_for_otp=on_ready_for_otp) + on_ready_for_otp=on_ready_for_otp, on_sucess=on_success) start_to_handle_sms(modem) except Exception as error: print(error)