use listener instead of rabittmq

This commit is contained in:
2022-03-24 10:57:57 +01:00
parent d0d3d59f27
commit 13a17e3d79
2 changed files with 18 additions and 9 deletions
+5 -8
View File
@@ -29,8 +29,9 @@ class CommandorPage:
def __init__(self): def __init__(self):
self.otp_value = None 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.contact = contact
self.on_success_listener = on_success
with sync_playwright() as pwright: with sync_playwright() as pwright:
firefox_user_agents = filter(lambda user_agent: "firefox" in user_agent.lower(), user_agent_list) firefox_user_agents = filter(lambda user_agent: "firefox" in user_agent.lower(), user_agent_list)
firefox_user_agents_list = list(firefox_user_agents) firefox_user_agents_list = list(firefox_user_agents)
@@ -75,9 +76,9 @@ class CommandorPage:
time.sleep(2) time.sleep(2)
# check and send successful event # 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() 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() t.start()
return e return e
@@ -137,11 +138,7 @@ class CommandorPage:
firstName=contact.first_name, lastName=contact.last_name, email=contact.mail, firstName=contact.first_name, lastName=contact.last_name, email=contact.mail,
passport=contact.passport, ccid=contact.ccid) passport=contact.passport, ccid=contact.ccid)
result.id = id result.id = id
channel = params.rabittmq_connection.channel() self.on_success_listener(result)
# default exchange, for 'hello' queue
print("will publish message:" + result.to_json())
channel.basic_publish(exchange='', routing_key=APPOINTMENT_QUEUE,
body=result.to_json())
def get_random_id_number_for_proxy() -> str: def get_random_id_number_for_proxy() -> str:
+13 -1
View File
@@ -151,6 +151,18 @@ def on_message_received(ch, method, properties, body):
is_finished = True 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(): def start_listen():
logger.info("start to listen to message queue") logger.info("start to listen to message queue")
receiver = MessageReceiver() receiver = MessageReceiver()
@@ -206,7 +218,7 @@ def start_book():
"password": params.PROXY_PASSWORD "password": params.PROXY_PASSWORD
} }
commandor.start_page(proxy=proxy, contact=modem.contact, 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) start_to_handle_sms(modem)
except Exception as error: except Exception as error:
print(error) print(error)