|
|
@@ -1,6 +1,6 @@
|
|
|
import yaml
|
|
|
from pathlib import Path
|
|
|
-from pydantic import BaseModel
|
|
|
+from pydantic import BaseModel, Field
|
|
|
from typing import List, Dict, Union,Optional,Any
|
|
|
from utils.pydantic_auto_field import AutoLoadModel
|
|
|
APP_PATH = Path(__file__).parent.parent
|
|
|
@@ -17,20 +17,19 @@ class Proxy(BaseModel):
|
|
|
file_path: Optional[str] = ''
|
|
|
startup: Optional[bool] = False
|
|
|
|
|
|
-
|
|
|
class Sub(AutoLoadModel):
|
|
|
url: Optional[str] = None
|
|
|
- start_port: Optional[int] = 9660 # Changed to int
|
|
|
+ start_port: Optional[int] = 9660
|
|
|
redis_url: Optional[str] = 'redis://localhost:6379/8'
|
|
|
file: Optional[str] = None
|
|
|
temp_dir: Optional[str] = str(PROXY_POLL_DIR / "temp")
|
|
|
auto_start: Optional[bool] = True
|
|
|
proxies: Optional[Dict[Union[int,str], Proxy]] = {}
|
|
|
+
|
|
|
def __init__(self, **data):
|
|
|
- super().__init__(**data)
|
|
|
- # Convert proxies dictionary values to Proxy objects
|
|
|
- if self.proxies:
|
|
|
- self.proxies = {k: Proxy(**v) if isinstance(v, dict) else v for k, v in self.proxies.items()}
|
|
|
+ super().__init__(**data)
|
|
|
+ if self.proxies:
|
|
|
+ self.proxies = {k: Proxy(**v) if isinstance(v, dict) else v for k, v in self.proxies.items()}
|
|
|
|
|
|
class Browser(BaseModel):
|
|
|
exe_path: Optional[str] = str(REPO_BASE_DIR / r"download\chrome-win\chrome.exe")
|
|
|
@@ -49,11 +48,13 @@ class Config(BaseModel):
|
|
|
sqluri: Optional[str] = r'G:\code\upwork\zhang_crawl_bio\output\temp.db'
|
|
|
browser: Optional[Browser] = Browser()
|
|
|
backend: Optional[Backend] = Backend()
|
|
|
- redis_port: Optional[int] = None # Changed to int
|
|
|
+ worker_backend: Optional[Backend] = Field(default_factory=lambda: Backend(host="localhost", port=8003))
|
|
|
+ redis_port: Optional[int] = None
|
|
|
+
|
|
|
def save(self):
|
|
|
config_path = get_config_path()
|
|
|
with open(config_path, "w", encoding="utf-8") as file:
|
|
|
- yaml.dump(self.model_dump(), file, encoding="utf-8", )
|
|
|
+ yaml.dump(self.model_dump(), file)
|
|
|
return self
|
|
|
|
|
|
def get_config_path():
|
|
|
@@ -66,19 +67,14 @@ def read_config(config_path: Path):
|
|
|
return config
|
|
|
with open(config_path, "r", encoding="utf-8") as file:
|
|
|
config_dict = yaml.safe_load(file)
|
|
|
- config = Config(**config_dict)
|
|
|
- return config
|
|
|
-config = read_config(get_config_path())
|
|
|
+ return Config(**config_dict)
|
|
|
|
|
|
-import os
|
|
|
-
|
|
|
-WORKER_SERVICE_URL = os.getenv("WORKER_SERVICE_URL", "http://localhost:8003")
|
|
|
+config = read_config(get_config_path())
|
|
|
+WORKER_SERVICE_URL = f"http://{config.worker_backend.host}:{config.worker_backend.port}"
|
|
|
|
|
|
def main():
|
|
|
print(config)
|
|
|
- config.browser = Browser()
|
|
|
- config.save(
|
|
|
-
|
|
|
- )
|
|
|
+ config.save()
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
main()
|