Skip to content

Commit

Permalink
Merge pull request #84 from gerardcl/python-depenecies-upgrades-and-i…
Browse files Browse the repository at this point in the history
…mprove-builds

Python depenecies upgrades and improve builds
  • Loading branch information
gerardcl authored Oct 23, 2021
2 parents 76ec65a + b2972eb commit c2c7ee1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8, 3.9]

steps:
Expand All @@ -30,7 +31,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-cov
if [ -f setup.py ]; then python setup.py install; fi
python setup.py install
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand All @@ -39,4 +40,6 @@ jobs:
flake8 src --count --exit-zero --max-complexity=11 --max-line-length=127 --statistics
- name: Test with pytest
run: |
PYTHONPATH=src python -m pytest --junitxml=tests.xml -o junit_family=xunit2 --cov-report term-missing --cov-report xml --cov=src -o testpaths=tests
python -m pytest --junitxml=tests.xml -o junit_family=xunit2 --cov-report term-missing --cov-report xml --cov=src -o testpaths=tests
env:
PYTHONPATH: "src"
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v3.2.0 (2021-10-23)

* Upgrade to Selenium 4
* Cryptography depends on Rust
* Fixes [#83](https://github.com/gerardcl/renfe-cli/issues/83)

## v3.1.0 (2021-09-13)

* Expose search timeout as a CLI flag and default to 3 seconds.
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='renfe-cli',
version='3.1.0',
version='3.2.0',
description='Get faster RENFE Spanish Trains timetables in your terminal',
long_description=read_md('README.md'),
keywords='Get faster RENFE Spanish Trains timetables terminal',
Expand All @@ -22,11 +22,12 @@
py_modules=['renfe-cli'],
include_package_data=True,
install_requires=[
'setuptools<58.3.0',
'setuptools-rust==0.12.1',
'setuptools==58.3.0',
'beautifulsoup4==4.10.0',
'html5lib==1.1',
'selenium==3.141.0',
'webdriver-manager==3.4.2',
'selenium==4.0.0',
'webdriver-manager==3.5.1',
'requests==2.26.0'
],
entry_points="""
Expand Down
14 changes: 11 additions & 3 deletions src/renfe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def main():
print(colorama.Fore.GREEN + f"Searching timetable for date: {get_date(int(options.days))}")
print(colorama.Fore.GREEN + f"From {origin_name} to {destination_name}" + colorama.Fore.RESET)
print(colorama.Fore.GREEN + "Be patient, navigating through renfe site now..." + colorama.Fore.RESET)
times = get_timetable(origin_name, destination_name, int(options.days), options.browser, int(options.search_timeout))
times = get_timetable(
origin_name,
destination_name,
int(options.days),
options.browser,
int(options.search_timeout))
print(colorama.Fore.GREEN + "=======================TIMETABLE======================")
print(colorama.Fore.GREEN + " {:<10} | {:<10} | {:<10} | {:<10} ".format(
'Train', 'Departure', 'Arrival', 'Duration'))
Expand All @@ -42,9 +47,12 @@ def main():
print(colorama.Fore.GREEN + "======================================================" + colorama.Fore.RESET)

if not times:
print(colorama.Fore.YELLOW + "Timetable was empty. Maybe no more trains for today? Also, try increasing search timeout (-e flag, see help). Please, open an issue if problem does persist." + colorama.Fore.RESET)
print(colorama.Fore.YELLOW + "Timetable was empty. \
Maybe no more trains for today? \
Also, try increasing search timeout (-e flag, see help). \
Please, open an issue if problem does persist." + colorama.Fore.RESET)

except RenfeException as err:
except (RenfeException, ValueError) as err:
logging.error(err)
logging.error(
"No timetables found... Check your inputs and enable debug. If the problem persists,"
Expand Down
35 changes: 23 additions & 12 deletions src/renfe/timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
os.environ['WDM_LOG_LEVEL'] = '0'


def get_timetable(origin: str, destination: str, days_from_today: int = 0, browser: str = "firefox", search_timeout: int = 3) -> List[Set]:
def get_timetable(
origin: str,
destination: str,
days_from_today: int = 0,
browser: str = "firefox",
search_timeout: int = 3) -> List[Set]:
soup = get_soup(browser, origin, destination, days_from_today, search_timeout)
types = get_types(soup)
durations = get_durations(soup)
Expand All @@ -22,18 +27,24 @@ def get_timetable(origin: str, destination: str, days_from_today: int = 0, brows

def get_browser(type: str) -> Union[Firefox, Chrome]:
global browser
if type == "firefox":
from webdriver_manager.firefox import GeckoDriverManager
firefox_options = webdriver.FirefoxOptions()
firefox_options.set_headless()
browser = webdriver.Firefox(executable_path=GeckoDriverManager().install(), firefox_options=firefox_options)
try:
if type == "firefox":
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options
firefox_options = Options()
firefox_options.add_argument("--headless")
browser = webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=firefox_options)
else: # chrome
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=chrome_options)

browser.implicitly_wait(10) # wait up to 10 seconds while trying to locate elements
else: # chrome
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = webdriver.ChromeOptions()
chrome_options.set_headless()
browser = webdriver.Chrome(executable_path=ChromeDriverManager().install(), chrome_options=chrome_options)
browser.implicitly_wait(10) # wait up to 10 seconds while trying to locate elements

except ValueError as ex:
raise ex

return browser

Expand Down

0 comments on commit c2c7ee1

Please sign in to comment.