From d7561956a153eafaa730337850a6077f3eecd313 Mon Sep 17 00:00:00 2001 From: Jimmy Situ Date: Sun, 3 Nov 2024 13:45:10 +0800 Subject: [PATCH] Update code for github actions --- .github/workflows/python-package.yml | 16 +++++++++------- msfinance/stocks.py | 13 ++++++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 8b36814..a590c94 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -30,12 +30,12 @@ jobs: uses: browser-actions/setup-chrome@v1.7.2 with: chrome-version: 126 - - name: Set Chrome directory in path - run: | - CHROME_DIR=$(dirname "${{ steps.setup_chrome.outputs.chrome-path }}") - echo "CHROME_DIR: $CHROME_DIR" - echo "$CHROME_DIR" >> $GITHUB_PATH - cat $GITHUB_PATH +# - name: Set Chrome directory in path +# run: | +# CHROME_DIR=$(dirname "${{ steps.setup_chrome.outputs.chrome-path }}") +# echo "CHROME_DIR: $CHROME_DIR" +# echo "$CHROME_DIR" >> $GITHUB_PATH +# cat $GITHUB_PATH - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: @@ -52,6 +52,8 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest + env: + CHROME_PATH: ${{ steps.setup_chrome.outputs.chrome-path }} run: | - echo "Path: $PATH" + echo "Chrome path: $CHROME_PATH" pytest --log-cli-level=DEBUG tests/test_stocks.py diff --git a/msfinance/stocks.py b/msfinance/stocks.py index 8e559e9..69a0b4a 100644 --- a/msfinance/stocks.py +++ b/msfinance/stocks.py @@ -59,6 +59,10 @@ def __init__(self, debug=False, browser='chrome', database='msfinance.db3', sess # Setup driver if browser == 'chrome': + if os.environ.get('CHROME_PATH') is not None: + self.chrome_path = os.environ.get('CHROME_PATH') + else: + self.chrome_path = None self.setup_chrome_driver(proxy) else: # Default: firefox @@ -526,17 +530,20 @@ 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, + options=self.options, + browser_executable_path=self.chrome_path, version_main=126, use_subprocess=True, user_multi_procs=True, service=webdriver.ChromeService(ChromeDriverManager(driver_version='126').install()), - options=self.options) + debug=self.debug, + ) elif self.driver_type == 'stealth': # Initialize the WebDriver (e.g., Chrome) self.driver = webdriver.Chrome( service=webdriver.ChromeService(ChromeDriverManager(driver_version='126').install()), - options=self.options) + options=self.options, + ) # Apply selenium-stealth to the WebDriver stealth(self.driver,