mirror of
https://github.com/BoPeng/ai-marketplace-monitor.git
synced 2025-12-23 22:28:18 -05:00
revert rotating vpn patch
This commit is contained in:
@@ -140,7 +140,7 @@ class Config(Generic[TAIConfig, TItemConfig, TMarketplaceConfig]):
|
||||
)
|
||||
marketplace_class = supported_marketplaces[market_type]
|
||||
self.marketplace[marketplace_name] = marketplace_class.get_config(
|
||||
name=marketplace_name, monitor_config=self.monitor, **marketplace_config
|
||||
name=marketplace_name, **marketplace_config
|
||||
)
|
||||
lan = self.marketplace[marketplace_name].language
|
||||
if lan is None:
|
||||
|
||||
@@ -275,8 +275,8 @@ class FacebookMarketplace(Marketplace):
|
||||
|
||||
def login(self: "FacebookMarketplace") -> None:
|
||||
assert self.browser is not None
|
||||
|
||||
self.page = self.create_page(swap_proxy=True)
|
||||
context = self.browser.new_context()
|
||||
self.page = context.new_page()
|
||||
|
||||
# Navigate to the URL, no timeout
|
||||
self.goto_url(self.initial_url)
|
||||
|
||||
@@ -7,15 +7,7 @@ from typing import Any, Callable, Generator, Generic, List, Type, TypeVar
|
||||
from playwright.sync_api import Browser, ElementHandle, Locator, Page # type: ignore
|
||||
|
||||
from .listing import Listing
|
||||
from .utils import (
|
||||
BaseConfig,
|
||||
Currency,
|
||||
KeyboardMonitor,
|
||||
MonitorConfig,
|
||||
Translator,
|
||||
convert_to_seconds,
|
||||
hilight,
|
||||
)
|
||||
from .utils import BaseConfig, Currency, KeyboardMonitor, Translator, convert_to_seconds, hilight
|
||||
|
||||
|
||||
class MarketPlace(Enum):
|
||||
@@ -351,7 +343,6 @@ class MarketplaceConfig(MarketItemCommonConfig):
|
||||
# name of market, right now facebook is the only supported one
|
||||
market_type: str | None = MarketPlace.FACEBOOK.value
|
||||
language: str | None = None
|
||||
monitor_config: MonitorConfig | None = None
|
||||
|
||||
def handle_market_type(self: "MarketplaceConfig") -> None:
|
||||
if self.market_type is None:
|
||||
@@ -479,32 +470,6 @@ class Marketplace(Generic[TMarketplaceConfig, TItemConfig]):
|
||||
self.browser = None
|
||||
self.page = None
|
||||
|
||||
def create_page(self: "Marketplace", swap_proxy: bool = False) -> Page:
|
||||
assert self.browser is not None
|
||||
|
||||
# if there is an existing page, asked to swap_proxy, and there is an proxy_server
|
||||
# setting with multiple proxies
|
||||
if (
|
||||
self.page
|
||||
and swap_proxy
|
||||
and self.config.monitor_config is not None
|
||||
and isinstance(self.config.monitor_config.proxy_server, list)
|
||||
and len(self.config.monitor_config.proxy_server) > 1
|
||||
):
|
||||
self.page.close()
|
||||
self.page = None
|
||||
|
||||
if self.page is None:
|
||||
context = self.browser.new_context(
|
||||
proxy=(
|
||||
None
|
||||
if self.config.monitor_config is None
|
||||
else self.config.monitor_config.get_proxy_options()
|
||||
)
|
||||
)
|
||||
self.page = context.new_page()
|
||||
return self.page
|
||||
|
||||
def goto_url(self: "Marketplace", url: str, attempt: int = 0) -> None:
|
||||
try:
|
||||
assert self.page is not None
|
||||
|
||||
@@ -394,7 +394,9 @@ class MarketplaceMonitor:
|
||||
# Open a new browser page.
|
||||
self.load_config_file()
|
||||
assert self.config is not None
|
||||
self.browser = self.playwright.chromium.launch(headless=self.headless)
|
||||
self.browser = self.playwright.chromium.launch(
|
||||
headless=self.headless, proxy=self.config.monitor.get_proxy_options()
|
||||
)
|
||||
#
|
||||
assert self.browser is not None
|
||||
while True:
|
||||
@@ -550,7 +552,9 @@ class MarketplaceMonitor:
|
||||
self.logger.info(
|
||||
f"""{hilight("[Search]", "info")} Starting a browser because the item was not checked before."""
|
||||
)
|
||||
self.browser = self.playwright.chromium.launch(headless=self.headless)
|
||||
self.browser = self.playwright.chromium.launch(
|
||||
headless=self.headless, proxy=self.config.monitor.get_proxy_options()
|
||||
)
|
||||
marketplace.set_browser(self.browser)
|
||||
|
||||
# ignore enabled
|
||||
|
||||
@@ -302,14 +302,10 @@ def test_config(config_file: Callable, config_content: str, acceptable: bool) ->
|
||||
config = Config([cfg])
|
||||
# assert the types
|
||||
for key, value in asdict(config.marketplace["facebook"]).items():
|
||||
if key == "monitor_config":
|
||||
continue
|
||||
assert isinstance(value, key_types[key]), f"{key} must be of type {key_types[key]}"
|
||||
|
||||
for item_cfg in config.item.values():
|
||||
for key, value in asdict(item_cfg).items():
|
||||
if key == "monitor_config":
|
||||
continue
|
||||
assert isinstance(value, key_types[key]), f"{key} must be of type {key_types[key]}"
|
||||
# test if all elements can be frozen
|
||||
for attr in ("item", "ai", "user", "marketplae"):
|
||||
|
||||
Reference in New Issue
Block a user