Skip to content

Commit

Permalink
Update code for github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmysitu committed Nov 3, 2024
1 parent 88dc916 commit d756195
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
uses: browser-actions/[email protected]
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:
Expand All @@ -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
13 changes: 10 additions & 3 deletions msfinance/stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d756195

Please sign in to comment.