porbleme of sync resolved
This commit is contained in:
+11
-11
@@ -22,14 +22,14 @@ class ResultEnum(Enum):
|
||||
PENDING = "PENDING"
|
||||
|
||||
|
||||
class Tls(threading.local):
|
||||
class TlsPlaywright(threading.local):
|
||||
def __init__(self) -> None:
|
||||
self.playwright = sync_playwright().start()
|
||||
self.playwright = params.SINGLE_PLAYWRIGHT_INSTANCE
|
||||
print("Create playwright instance in Thread", threading.current_thread().name)
|
||||
|
||||
|
||||
class Worker:
|
||||
tls = Tls()
|
||||
class ResultChecker:
|
||||
tls = TlsPlaywright()
|
||||
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger("Worker")
|
||||
@@ -38,7 +38,7 @@ class Worker:
|
||||
try:
|
||||
self.browser = playwright.webkit.launch(headless=False, timeout=90000, proxy=proxy)
|
||||
device = random.choice(params.DEVICES)
|
||||
self.logger.info("device is " + device)
|
||||
self.logger.info("模拟设备: " + device)
|
||||
pixel_2 = self.tls.playwright.devices[device]
|
||||
context = self.browser.new_context(**pixel_2, locale='en-GB')
|
||||
self.page = context.new_page()
|
||||
@@ -104,14 +104,14 @@ if __name__ == '__main__':
|
||||
# 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
|
||||
collection = db_manager.get_all_successful_items()
|
||||
collection = db_manager.get_all_successful_items_for_day()
|
||||
count = 0
|
||||
result_pojo = ReserveResultPojo(type=PublishType.SUCCESS, phone="0649614591", email="panleicim@gmail.com",
|
||||
message="SUCCESS", firstName="Lei", lastName="PAN")
|
||||
message="SUCCESS", firstName="Lei", lastName="PAN", url='https://api.ipify.org')
|
||||
result_list = []
|
||||
for appointment in collection.stream():
|
||||
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||
result_list.append(result_pojo)
|
||||
# for appointment in collection.stream():
|
||||
# reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||
result_list.append(result_pojo)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=2) as executor:
|
||||
for reserve in result_list:
|
||||
@@ -119,5 +119,5 @@ if __name__ == '__main__':
|
||||
if reserve.accepted:
|
||||
print("status is " + reserve.accepted)
|
||||
if reserve.accepted is None or ResultEnum.PENDING.value == reserve.accepted:
|
||||
executor.submit(Worker().run, reserve, collection)
|
||||
executor.submit(ResultChecker().run, reserve, collection)
|
||||
print(count)
|
||||
|
||||
+5
-1
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from typing import Union
|
||||
|
||||
import firebase_admin
|
||||
from firebase_admin import credentials, firestore
|
||||
@@ -15,6 +16,7 @@ MAIL_COLLECTION_NAME = "mail_list"
|
||||
SIM_INFOS = "sim_infos"
|
||||
TIMEOUT = "timeout_items"
|
||||
|
||||
|
||||
class DataManager:
|
||||
batch_size = 20
|
||||
|
||||
@@ -30,8 +32,10 @@ class DataManager:
|
||||
def get_all_successful_items(self):
|
||||
return self.get_all_successful_items_for_day(str(datetime.date.today()))
|
||||
|
||||
def get_all_successful_items_for_day(self, day):
|
||||
def get_all_successful_items_for_day(self, day, source_from: Union[str, None]):
|
||||
doc_ref = self._db.collection(day)
|
||||
if source_from is not None:
|
||||
doc_ref.where()
|
||||
return doc_ref
|
||||
|
||||
def save_sim_info(self, sim_info: SimInfoPojo):
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import configparser
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from db.DbManager import DataManager
|
||||
from logs.LogSender import LogSender
|
||||
|
||||
@@ -9,6 +11,7 @@ oracle_log_sender = LogSender()
|
||||
# proxy
|
||||
PROXY_SERVER = "http://gw.ntnt.io:5959"
|
||||
PROXY_PASSWORD = "94sY7zwBG13i"
|
||||
SINGLE_PLAYWRIGHT_INSTANCE = sync_playwright().start()
|
||||
|
||||
DEVICES = ['iPad (gen 6)', 'iPad (gen 6) landscape', 'iPad (gen 7)', 'iPad (gen 7) landscape', 'iPad Mini',
|
||||
'iPad Mini landscape', 'iPad Pro 11', 'iPad Pro 11 landscape', 'iPhone 6', 'iPhone 6 landscape',
|
||||
|
||||
@@ -5,8 +5,6 @@ import threading
|
||||
import time
|
||||
from typing import Union
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
import params
|
||||
from params import PROXY_SERVER, PROXY_PASSWORD
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||
@@ -33,7 +31,7 @@ def get_random_wait_time() -> float:
|
||||
|
||||
class Tls(threading.local):
|
||||
def __init__(self) -> None:
|
||||
self.playwright = sync_playwright().start()
|
||||
self.playwright = params.SINGLE_PLAYWRIGHT_INSTANCE
|
||||
|
||||
|
||||
class CommandorPage:
|
||||
|
||||
Reference in New Issue
Block a user