Skip to content

Commit

Permalink
Merge branch '0.3.0' into dmv1167-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
athuler authored Sep 29, 2024
2 parents 19a7a06 + 57e31d0 commit 9fcd2f1
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

name: Testing Package

on: push
on: [push, pull_request]


permissions:
Expand All @@ -30,4 +30,4 @@ jobs:
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest
pytest
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Changelog


## 0.3.0 (Unreleased)

### Added

- `TransportationSystem.getRouteById()` method to get a Route object by its ID
- `TransportationSystem.getStopById()` method to get a Stop object by its ID

### Changed

- `Route.id` is now handled as a string

### Removed


## 0.2.2 (2024-09-10)

### Added


### Changed

- Fixed key error while fetching systems. (#22)

### Removed


## 0.2.1 (2024-08-18)

### Added
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![PyPI - Version](https://img.shields.io/pypi/v/passiogo?label=Latest%20Version&link=https%3A%2F%2Fpypi.org%2Fproject%2FPassioGo%2F)](https://pypi.org/project/PassioGo/)
[![Pepy Total Downlods](https://img.shields.io/pepy/dt/PassioGo)](https://www.pepy.tech/projects/passiogo)
[![GitHub Testing](https://img.shields.io/github/actions/workflow/status/athuler/passiogo/testing.yml?branch=main&label=tests)](https://github.com/athuler/PassioGo)
[![Documentation Status](https://readthedocs.org/projects/passiogo/badge/?version=latest)](https://passiogo.readthedocs.io/en/latest/?badge=latest)


Expand All @@ -20,7 +21,7 @@ pip install passiogo

## Documentation

Project documentation for the latest stable version is available at [passiogo.readthedocs.io](https://passiogo.readthedocs.io/). Documentation for other versions is available at [passiogo.readthedocs.io/en/X.X.X](https://passiogo.readthedocs.io/en/0.1.2/).
Project documentation for the latest stable version is available at [passiogo.readthedocs.io](https://passiogo.readthedocs.io/). Documentation for other versions is available at [passiogo.readthedocs.io/en/X.X.X](https://passiogo.readthedocs.io/en/0.3.0/).

The documentation is built using `mkdocs` and can be rebuilt using the following:

Expand Down
41 changes: 41 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ passiogo.getSystemFromID(1068).getRoutes()
<passiogo.Route at 0x1d62db3fca0>]
```

### `TransportationSystem.getRouteById()`

Get the route for the appropriate ID.

**Input**:

- **routeId** (*str*): ID of the desired route
- **appVersion** (*int*): Version of the application (Default: 1)
- **amount** (*int*): Unknown (Default: 1)

**Output**: [`Route`](#route) or *None* if no match

```python
passiogo.getSystemFromID(1068).getRouteById(133007)
```

```
<passiogo.Route at 0x1c26a30a1c0>
```


### `TransportationSystem.getStops()`

Gets all stops for the given transportation system.
Expand Down Expand Up @@ -147,6 +168,26 @@ passiogo.getSystemFromID(1068).getStops()
<passiogo.Stop at 0x1d62da5a700>]
```

### `TransportationSystem.getStopById()`

Get the stop for the appropriate ID.

**Input**:

- **stopId** (*str*): ID of the desired stop
- **appVersion** (*int*): Version of the application (Default: 1)
- **sA** (*int*): Unknown (Default: 1)

**Output**: [`Stop`](#stop) or *None* if no match

```python
passiogo.getSystemFromID(3499).getStopById(140059)
```

```
<passiogo.Stop at 0x1c2690238e0>
```

### `TransportationSystem.getSystemAlerts()`

Gets all alerts for the corresponding transportation system.
Expand Down
42 changes: 41 additions & 1 deletion passiogo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ def getRouteById(self, routeId):
return None


def getRouteById(
self,
routeId: str,
appVersion: int = 1,
amount: int = 1
) -> "Route":
"""
Returns a Route object corresponding to the provided ID.
"""
allRoutes = self.getRoutes(
appVersion = appVersion,
amount = amount
)

for route in allRoutes:
if str(route.id) == str(routeId):
return route
return None

def getStops(
self,
appVersion = 2,
Expand Down Expand Up @@ -315,6 +334,27 @@ def getStopById(self, stopId):
return None


def getStopById(
self,
stopId: str,
appVersion = 2,
sA = 1,
raw = False,
) -> "Stop":
"""
Returns the Stop object corresponding to the passed ID.
"""
allStops = self.getStops(
appVersion = appVersion,
sA = sA,
raw = raw,
)

for stop in allStops:
if str(stop.id) == str(stopId):
return stop
return None

def getSystemAlerts(
self,
appVersion = 1,
Expand Down Expand Up @@ -545,7 +585,7 @@ class Route:

def __init__(
self,
id: int,
id: str,
groupId: int = None,
groupColor: str = None,
name: str = None,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='PassioGo',
version="0.2.2",
version="0.3.0",
description="An unofficial API for Passio Go",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
8 changes: 7 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ def test_getSystemFromId():
testSystem = passiogo.getSystemFromID(1068)
assert True

def test_getRouteById():
testSystem.getRouteById(133007)
pass

@pytest.mark.parametrize("system", pytest.allSystems, ids=ids)
def test_getAllRoutes(system):
system.getRoutes()

def test_getStopById():
testSystem.getStopById(140059)
pass

@pytest.mark.parametrize("system", pytest.allSystems, ids=ids)
def test_getAllStops(system):
Expand All @@ -41,4 +47,4 @@ def test_getSystemAlerts(system):
@pytest.mark.parametrize("system", pytest.allSystems, ids=ids)
def test_getVehicles(system):
system.getVehicles()


0 comments on commit 9fcd2f1

Please sign in to comment.