From 4be49ba2fa6718426b88e60e3da012dcb1b5098f Mon Sep 17 00:00:00 2001 From: Jimmy Situ Date: Mon, 28 Oct 2024 22:29:44 +0800 Subject: [PATCH] Update workflow add more debug log --- .github/workflows/python-package.yml | 2 +- examples/get_sp500.mp.py | 5 +++-- msfinance/stocks.py | 13 ++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 8e37284..0463ac4 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -49,4 +49,4 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest tests/test_stocks.py + pytest --log-cli-level=DEBUG tests/test_stocks.py diff --git a/examples/get_sp500.mp.py b/examples/get_sp500.mp.py index 12f9284..13e46a2 100755 --- a/examples/get_sp500.mp.py +++ b/examples/get_sp500.mp.py @@ -10,7 +10,7 @@ proxy = 'socks5://127.0.0.1:1088' # Create an engine -engine = create_engine('sqlite:///sp500.mt.db3', pool_size=5, max_overflow=10) +engine = create_engine('sqlite:///sp500.mp.db3', pool_size=5, max_overflow=10) # Create a session factory InitialSessionFactory = sessionmaker(bind=engine) @@ -22,6 +22,7 @@ ) sp500_tickers = initial_stock.get_sp500_tickers() +sp500_tickers = sorted(sp500_tickers) tickers_list = {} tickers_list['xnas'] = initial_stock.get_xnas_tickers() @@ -70,7 +71,7 @@ def initializer(): # Use ProcessPoolExecutor to process tickers in parallel max_workers = 4 # Adjust max_workers as needed -chunk_size = math.ceil(len(sp500_tickers) / max_workers) +chunk_size = 50 ticker_chunks = [sp500_tickers[i:i + chunk_size] for i in range(0, len(sp500_tickers), chunk_size)] with ProcessPoolExecutor(max_workers=max_workers, initializer=initializer) as executor: diff --git a/msfinance/stocks.py b/msfinance/stocks.py index 0e74c24..8e559e9 100644 --- a/msfinance/stocks.py +++ b/msfinance/stocks.py @@ -110,16 +110,13 @@ def reset_driver(self, retry_state=None): print(f" Time elapsed: {retry_state.seconds_since_start}") - if self.driver: + + # Setup a new driver instance + if isinstance(self.driver, (webdriver.Chrome, uc.Chrome)): self.driver.quit() - - # Assuming the driver is a Chrome or Firefox driver - # You might need to adjust this logic based on your actual driver setup - if isinstance(self.driver, webdriver.Chrome): - self.setup_chrome_driver(self.proxies['http']) - elif isinstance(self.driver, uc.Chrome): self.setup_chrome_driver(self.proxies['http']) else: + self.driver.quit() self.setup_firefox_driver(self.proxies['http']) @@ -529,6 +526,7 @@ def initialize_chrome_driver(self): # Initialize the driver based on the driver_type if self.driver_type == 'uc': self.driver = uc.Chrome( + debug=self.debug, version_main=126, use_subprocess=True, user_multi_procs=True, @@ -782,5 +780,6 @@ def get_xase_tickers(self): +