use same rabittmq connection

This commit is contained in:
2022-03-24 10:15:44 +01:00
parent 25207bb062
commit cd71577e71
6 changed files with 17 additions and 23 deletions
+2 -12
View File
@@ -4,7 +4,6 @@ import string
import threading
import time
import pika
from playwright.sync_api import sync_playwright
import params
@@ -136,25 +135,17 @@ class CommandorPage:
id = url.split("/")[-1]
result = ReserveResultPojo(type=PublishType.SUCCESS, phone=contact.phone, message=message, url=url,
firstName=contact.first_name, lastName=contact.last_name, email=contact.mail,
passport=contact.passport)
passport=contact.passport, ccid=contact.ccid)
result.id = id
_credentials = pika.PlainCredentials('scrapy_rabbitmq', '4x!hReCbA5v3heKWfPJV-Y')
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=params.rabittMQ_host,
port=params.rabittMQ_port,
credentials=_credentials))
channel = connection.channel()
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())
connection.close()
def get_random_id_number_for_proxy() -> str:
# write_the_valid_profiles_to_excel()
S = 8 # number of characters in the string.
# call random.choices() string module to find the string in Uppercase + numeric data.
ran = ''.join(random.choices(string.digits, k=S))
id_number = str(ran)
print("The randomly generated string is : " + str(ran)) # print the random data
@@ -162,7 +153,6 @@ def get_random_id_number_for_proxy() -> str:
def get_random_id_number() -> str:
# write_the_valid_profiles_to_excel()
S = 8 # number of characters in the string.
ran = ''.join(random.choices(string.digits, k=S))
id_number = "57" + str(ran)
+1 -1
View File
@@ -67,7 +67,7 @@ class ModemPool:
ccid_group = re.search("[0-9F]+", response)
ccid = ccid_group.group(0)
sim_position = index + 1
position = (slot_position - 1) * 15 + sim_position
position = (slot_position - 1) * len(self._port_list) + sim_position
if phone_number:
self._db_manager.save_sim_info(SimInfoPojo(phone=phone_number, ccid=ccid, position=position))
self._log_sender.send_log(phone_number, source=self.TAG, subject=SUBJECT_SIM_INFO,
+5
View File
@@ -1,3 +1,5 @@
import pika
from db.DbManager import DataManager
from logs.LogSender import LogSender
@@ -33,3 +35,6 @@ PROXY_PASSWORD = "M3PZAXgW5V27"
# rabittmq
rabittMQ_host = "rabbitmq.lpaconsulting.fr"
rabittMQ_port = 6672
_credentials = pika.PlainCredentials('scrapy_rabbitmq', '4x!hReCbA5v3heKWfPJV-Y')
rabittmq_connection = pika.BlockingConnection(
pika.ConnectionParameters(host='rabbitmq.lpaconsulting.fr', port=6672, credentials=_credentials))
+6 -1
View File
@@ -23,6 +23,7 @@ class ReserveResultPojo:
passport: str = ""
slot_position = None
sim_position = None
ccid: str = ""
@staticmethod
def from_firestore_dict(source):
@@ -49,6 +50,9 @@ class ReserveResultPojo:
if 'passport' in source:
passport = source['passport']
result.passport = passport
if 'ccid' in source:
ccid = source['ccid']
result.ccid = ccid
result.id = id
return result
@@ -64,7 +68,8 @@ class ReserveResultPojo:
u'passport': self.passport,
u'url': self.url,
u'sim_position': self.sim_position,
u'slot_position': self.slot_position
u'slot_position': self.slot_position,
u'ccid': self.ccid
}
return dest
-1
View File
@@ -11,7 +11,6 @@ def read_all_the_phone_number():
params.oracle_log_sender.send_log(msg="SIM卡自检开始", subject=LOG_SUBJECT_EVENT, type=TYPE_EVENT_RESET_ALL_SIM_CARDS)
slot_number = 16
slot_sum = 27
# card_pool.switch_to_slot(29)
params.firebase_store_manager.clear_all_sim_info()
for i in range(slot_number, slot_sum + 1):
card_pool.reset()
+3 -8
View File
@@ -1,24 +1,19 @@
import logging
import threading
from datetime import datetime
import pika
from params import rabittmq_connection
APPOINTMENT_QUEUE = "APPOINTMENT_QUEUE"
class MessageReceiver:
def __init__(self):
self._credentials = pika.PlainCredentials('scrapy_rabbitmq', '4x!hReCbA5v3heKWfPJV-Y')
def start_listener(self, callback):
t = threading.Thread(target=self._run, args=(callback,))
t.start()
def _run(self, callback):
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='rabbitmq.lpaconsulting.fr', port=6672, credentials=self._credentials))
channel = connection.channel()
channel = rabittmq_connection.channel()
channel.queue_declare(queue=APPOINTMENT_QUEUE)
channel.basic_consume(queue=APPOINTMENT_QUEUE,
auto_ack=True,