add mongoDb support

This commit is contained in:
Lei PAN
2022-06-16 09:26:49 +02:00
parent 8c536624b1
commit 636ef124d5
4 changed files with 35 additions and 9 deletions
+3 -2
View File
@@ -58,9 +58,10 @@ class DataManager:
def save(self, result: ReserveResultPojo):
id = result.url.split("/")[-1]
result.id = id
document_name = str(datetime.date.today())
doc_ref = self._db.collection(document_name).document(result.id)
collection_name = str(datetime.date.today())
doc_ref = self._db.collection(collection_name).document(result.id)
doc_ref.set(result.to_firestore_dict())
params.mongo_store_manager.insert_reserve_result(collection_name=collection_name, reserve=result)
def find_appointment_detail_via_phone(self, day, phone) -> ReserveResultPojo:
params.oracle_log_sender.send_read_db_event("find_appointment_detail_via_phone")
+29
View File
@@ -0,0 +1,29 @@
import logging
from pymongo import MongoClient
from pojo.ReserveResultPojo import ReserveResultPojo
MONGO_DB_URL = "91.121.210.60"
class MongoDbManager:
def __init__(self):
client = MongoClient(MONGO_DB_URL, username='appointment', password='Rdv@2022', authSource='appointment')
self.db = client.appointment
self.logger = logging.getLogger("mongoDb")
def insert_one(self, collection_name: str, dict: dict):
collection_to_use = self.db[collection_name]
collection_to_use.insert_one(dict)
def insert_reserve_result(self, collection_name, reserve: ReserveResultPojo):
try:
collection_to_use = self.db[collection_name]
collection_to_use.replace_one(filter={'_id': reserve.id, }, replacement=reserve.to_firestore_dict(),
upsert=True)
except Exception as Error:
print(Error)
if __name__ == '__main__':
db_manager = MongoDbManager()
+3 -5
View File
@@ -4,6 +4,7 @@ import string
import definitions
from db.DbManager import DataManager
from db.local_db_manager import LocalDbManager
from db.mongo_manager import MongoDbManager
from logs.LogSender import LogSender
from proxy.proxy_type import ProxyType
@@ -22,6 +23,8 @@ BRIGHT_DATA_MOBILE_PROXY_PASSWORD = "fk5f7c2z2c19"
PROXY_NAME_PREFIX_RES = "panleicim-res-fr-"
PROXY_NAME_PREFIX_CC = "panleicim-cc-fr-"
mongo_store_manager = MongoDbManager()
def get_proxy_name_prefix() -> str:
return PROXY_NAME_PREFIX_RES
@@ -42,11 +45,6 @@ def get_proxy(proxy_type: ProxyType):
"username": BRIGHT_DATA_PROXY_USERNAME,
"password": BRIGHT_DATA_PROXY_PASSWORD
}
# proxy = {
# "server": BRIGHT_DATA_PROXY_SERVER,
# "username": BRIGHT_DATA_MOBILE_PROXY_USERNAME,
# "password": BRIGHT_DATA_MOBILE_PROXY_PASSWORD
# }
return proxy
-2
View File
@@ -100,8 +100,6 @@ class CommandorPage:
while first_page is None:
first_page = self.start_browser(proxy, self.tls.playwright, devices)
proxy = params.get_proxy(self.proxy_type)
# wait for sms_code field
# self.clickOnValidBtn()
self.thread_event = e
otp_input = self.page.locator(OTP_FIELD_ID)
otp_input.wait_for(state='visible', timeout=TIME_OUT)