mirror of
https://github.com/RustyRaptor/PassioGo.git
synced 2026-12-03 15:45:22 -07:00
TransportationSystem object & documentation
This commit is contained in:
1 parent
b7dccb4b6a
commit
6c9ddce7d7
4 files changed
+212
-46
No files matched your search
@@ -1,3 +1,5 @@
|
||||
|
||||
/passiogo/__pycache__
|
||||
/tests/__pycache__
|
||||
/.ipynb_checkpoints
|
||||
Testing.ipynb
|
||||
@@ -1,9 +1,12 @@
|
||||
# Passio Go API
|
||||
|
||||
[](https://pypi.org/project/PassioGo/)
|
||||
[](https://www.pepy.tech/projects/passiogo)
|
||||
[](https://passiogo.readthedocs.io/en/latest/?badge=latest)
|
||||
|
||||
|
||||
|
||||
|
||||
An **unofficial** Python API for [Passio Go](https://passiogo.com/) allowing anyone to build transit-based applications for hundreds of Universities, Municipalities, Paratransit, and Airports.
|
||||
|
||||
|
||||
|
||||
+46
-6
@@ -1,7 +1,48 @@
|
||||
|
||||
# API Reference
|
||||
|
||||
## `getAllRoutes`
|
||||
## `TransportationSystem`
|
||||
|
||||
- **id** (*int*): ID of the system
|
||||
- **name** (*str*): The full name of the system
|
||||
- **username** (*str*): URL-friendly system name
|
||||
- **goAgencyName** (*str*): Display name of the system
|
||||
- **email** (*str*): Contact email address for the system
|
||||
- **goTestMode** (*bool*): Unknown
|
||||
- **name2** (*bool*): Unknown
|
||||
- **homepage** (*str*): URL to the agency's homepage
|
||||
- **logo** (*bool*): Unknown
|
||||
- **goRoutePlannerEnabled** (*bool*): Unknown
|
||||
- **goColor** (*str*): Unknown
|
||||
- **goSupportEmail** (*str*): Unknown
|
||||
- **goSharedCode** (*int*): Unknown
|
||||
- **goAuthenticationType** (*bool*): Unknown
|
||||
|
||||
|
||||
## `getSystems()`
|
||||
|
||||
Gets all systems supported by PassioGo.
|
||||
|
||||
**Inputs**:
|
||||
|
||||
- **appVersion** (*int*): Version of the application (Default: 2)
|
||||
- **sortMode** (*int*): Unknown (Default: 1)
|
||||
|
||||
**Returns**: *list* of [`TransportationSystem`](#transportationsystem)
|
||||
|
||||
|
||||
## `printAllSystemsMd()`
|
||||
|
||||
Prints all system names as a markdown list.
|
||||
|
||||
**Input**:
|
||||
|
||||
- **includeHtmlBreaks** (*bool*): Whether to include HTML line breaks (Default: True)
|
||||
|
||||
**Returns**: None
|
||||
|
||||
|
||||
## `getAllRoutes()`
|
||||
|
||||
Obtains every route for the selected system.
|
||||
|
||||
@@ -11,12 +52,11 @@ Obtains every route for the selected system.
|
||||
- **paramDigit**:
|
||||
- **amount**:
|
||||
|
||||
## `getAllStops`
|
||||
## `getAllStops()`
|
||||
|
||||
## `getSystemAlerts`
|
||||
## `getSystemAlerts()`
|
||||
|
||||
## `getBuses()`
|
||||
|
||||
## `getBuses`
|
||||
|
||||
## `getSystems`
|
||||
|
||||
## `printAllSystemsMd`
|
||||
+161
-40
@@ -1,10 +1,18 @@
|
||||
import json
|
||||
import requests
|
||||
import websocket
|
||||
import json
|
||||
|
||||
BASE_URL = "https://passiogo.com"
|
||||
|
||||
|
||||
### Helper Functions ###
|
||||
|
||||
def toIntInclNone(toInt):
|
||||
if toInt == None:
|
||||
return toInt
|
||||
return(int(toInt))
|
||||
|
||||
|
||||
def sendApiRequest(url, body):
|
||||
|
||||
# Send Request
|
||||
@@ -25,6 +33,158 @@ def sendApiRequest(url, body):
|
||||
return(response)
|
||||
|
||||
|
||||
|
||||
### Transportation Systems ###
|
||||
|
||||
|
||||
class TransportationSystem:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: int,
|
||||
name: str = None,
|
||||
username: str = None,
|
||||
goAgencyName: str = None,
|
||||
email: str = None,
|
||||
goTestMode: bool = None,
|
||||
name2: bool = None,
|
||||
homepage: str = None,
|
||||
logo: bool = None,
|
||||
goRoutePlannerEnabled: bool = None,
|
||||
goColor: str = None,
|
||||
goSupportEmail: str = None,
|
||||
goSharedCode: int = None,
|
||||
goAuthenticationType: bool = None
|
||||
):
|
||||
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.username = username
|
||||
self.goAgencyName = goAgencyName
|
||||
self.email = email
|
||||
self.goTestMode = goTestMode
|
||||
self.name2 = name2
|
||||
self.homepage = homepage
|
||||
self.logo = logo
|
||||
self.goRoutePlannerEnabled = goRoutePlannerEnabled
|
||||
self.goColor = goColor
|
||||
self.goSupportEmail = goSupportEmail
|
||||
self.goSharedCode = goSharedCode
|
||||
self.goAuthenticationType = goAuthenticationType
|
||||
|
||||
self.checkTypes()
|
||||
|
||||
def checkTypes(self) -> None:
|
||||
# id : int
|
||||
assert type(self.id) == int, f"'id' parameter must be an int not {type(self.id)}"
|
||||
|
||||
# name : str or None
|
||||
assert (type(self.name) == str or self.name is None), f"'name' parameter must be a str not {type(self.name)}"
|
||||
|
||||
# username : str or None
|
||||
assert (type(self.username) == str or self.username is None), f"'username' parameter must be a str not {type(self.username)}"
|
||||
|
||||
# goAgencyName : str or None
|
||||
assert (type(self.goAgencyName) == str or self.goAgencyName is None), f"'goAgencyName' parameter must be a str not {type(self.goAgencyName)}"
|
||||
|
||||
# email : str or None
|
||||
assert (type(self.email) == str or self.email is None), f"'email' parameter must be a str not {type(self.email)}"
|
||||
|
||||
# goTestMode : bool or None
|
||||
assert (type(self.goTestMode) == bool or self.goTestMode is None), f"'goTestMode' parameter must be a bool not {type(self.goTestMode)}"
|
||||
|
||||
# name2 : bool or None
|
||||
assert (type(self.name2) == bool or self.name2 is None), f"'name2' parameter must be a bool not {type(self.name2)}"
|
||||
|
||||
# homepage : str or None
|
||||
assert (type(self.homepage) == str or self.homepage is None), f"'homepage' parameter must be a str not {type(self.homepage)}"
|
||||
|
||||
# logo : bool or None
|
||||
assert (type(self.logo) == bool or self.logo is None), f"'logo' parameter must be a bool not {type(self.logo)}"
|
||||
|
||||
# goRoutePlannerEnabled : bool or None
|
||||
assert (type(self.goRoutePlannerEnabled) == bool or self.goRoutePlannerEnabled is None), f"'goRoutePlannerEnabled' parameter must be a bool not {type(self.goRoutePlannerEnabled)}"
|
||||
|
||||
# goColor : str or None
|
||||
assert (type(self.goColor) == str or self.goColor is None), f"'goColor' parameter must be a str not {type(self.goColor)}"
|
||||
|
||||
# goSupportEmail : str or None
|
||||
assert (type(self.goSupportEmail) == str or self.goSupportEmail is None), f"'goSupportEmail' parameter must be a str not {type(self.goSupportEmail)}"
|
||||
|
||||
# goSharedCode : int or None
|
||||
assert (type(self.goSharedCode) == int or self.goSharedCode is None), f"'goSharedCode' parameter must be a int not {type(self.goSharedCode)}"
|
||||
|
||||
# goAuthenticationType : bool or None
|
||||
assert (type(self.goAuthenticationType) == bool or self.goAuthenticationType is None), f"'goAuthenticationType' parameter must be a bool not {type(self.goAuthenticationType)}"
|
||||
|
||||
|
||||
def getSystems(
|
||||
appVersion = 2,
|
||||
sortMode = 1,
|
||||
) -> list[TransportationSystem]:
|
||||
'''
|
||||
Gets all systems. Returns a list of TransportationSystem.
|
||||
|
||||
sortMode: Unknown
|
||||
appVersion:
|
||||
<2: Error
|
||||
2: Valid
|
||||
'''
|
||||
|
||||
|
||||
# Initialize & Send Request
|
||||
url = f"{BASE_URL}/mapGetData.php?getSystems={appVersion}&sortMode={sortMode}&credentials=1"
|
||||
systems = sendApiRequest(url, None)
|
||||
|
||||
|
||||
# Handle Request Error
|
||||
if(systems == None):
|
||||
return([])
|
||||
|
||||
|
||||
allSystems = []
|
||||
for system in systems["all"]:
|
||||
|
||||
# Convert Empty Strings To None Objects
|
||||
for parameter in system.keys():
|
||||
if system[parameter] == '':
|
||||
system[parameter] = None
|
||||
try:
|
||||
allSystems.append(TransportationSystem(
|
||||
id = int(system["id"]),
|
||||
name = system["fullname"],
|
||||
username = system["username"],
|
||||
goAgencyName = system["goAgencyName"],
|
||||
email = system["email"],
|
||||
goTestMode = bool(int(system["goTestMode"])),
|
||||
name2 = bool(int(system["name2"])),
|
||||
homepage = system["homepage"],
|
||||
logo = bool(int(system["logo"])),
|
||||
goRoutePlannerEnabled = bool(int(system["goRoutePlannerEnabled"])),
|
||||
goColor = system["goColor"],
|
||||
goSupportEmail = system["goSupportEmail"],
|
||||
goSharedCode = toIntInclNone(system["goSharedCode"]),
|
||||
goAuthenticationType = bool(int(system["goAuthenticationType"])),
|
||||
))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print(system)
|
||||
return()
|
||||
|
||||
|
||||
return(allSystems)
|
||||
|
||||
|
||||
def printAllSystemsMd(
|
||||
includeHtmlBreaks = True
|
||||
):
|
||||
systems = getSystems()
|
||||
|
||||
for system in systems:
|
||||
print(f"- {system.name}{'<br/>' if includeHtmlBreaks else ''}")
|
||||
|
||||
|
||||
|
||||
def getAllRoutes(
|
||||
systemSelected,
|
||||
paramDigit = 1,
|
||||
@@ -156,45 +316,6 @@ def getBuses(
|
||||
return(buses)
|
||||
|
||||
|
||||
def getSystems(
|
||||
paramDigit = 2,
|
||||
sortMode = 1,
|
||||
deviceId = 43647468
|
||||
):
|
||||
"""
|
||||
Gets all system alerts for the selected system.
|
||||
=========
|
||||
systemSelected: system from which to get content
|
||||
paramDigit:
|
||||
0: Error
|
||||
>=1: Valid
|
||||
"""
|
||||
|
||||
|
||||
# Initialize & Send Request
|
||||
url = f"{BASE_URL}/mapGetData.php?getSystems={paramDigit}&sortMode={sortMode}&deviceId={deviceId}&credentials=1"
|
||||
systems = sendApiRequest(url, None)
|
||||
|
||||
|
||||
# Handle Request Error
|
||||
if(systems == None):
|
||||
return(None)
|
||||
|
||||
|
||||
|
||||
return(systems)
|
||||
|
||||
|
||||
def printAllSystemsMd(
|
||||
paramDigit = 2,
|
||||
sortMode = 1,
|
||||
deviceId = 43647468,
|
||||
includeHtml = True
|
||||
):
|
||||
systems = getSystems(paramDigit,sortMode,deviceId)
|
||||
|
||||
for system in systems["all"]:
|
||||
print(f"- {system['fullname']}{'<br/>' if includeHtml else ''}")
|
||||
|
||||
|
||||
# Launch WebSocket
|
||||
|
||||
Reference in new issue
Block a user