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