PK!fuu!python_ottawa_transit/__init__.pyfrom python_ottawa_transit import api from python_ottawa_transit.api import OCTransportApi __all__ = ["api", "cli"] PK!m` ` python_ottawa_transit/api.pyimport json from functools import wraps from string import Template import typing from urllib.request import urlopen from urllib.parse import urlencode __version__ = "0.1.0" API_VERSION = "1.2" ENDPOINT = Template(f"https://api.octranspo1.com/v$version/$method") def transform_method_name(name: str) -> str: return "".join(word.capitalize() for word in name.split("_")) def transform_argument_name(name: str) -> str: parts = name.split("_") return parts[0] + "".join(part.capitalize() for part in parts[1:]) def transform_arguments(kwargs) -> dict: return {transform_argument_name(key): value for key, value in kwargs.items()} def make_oc_transport_request(transform_name=False, transform_args=False): def outer_func(func): @wraps(func) def inner_func(self, **kwargs): name = func.__name__ method_name = transform_method_name(name) if transform_name else name method_args = transform_arguments(kwargs) if transform_args else kwargs req_url = ENDPOINT.substitute(version=self.version, method=method_name) req_func = self._build_request(req_url, params=method_args) response = req_func() return getattr(self, f"_{name}")(response) return inner_func return outer_func class OCTransportApi: def __init__( self, app_id: str, app_key: str, format="json", version=API_VERSION ) -> None: self._app_id = app_id self._app_key = app_key self._format = format self.version = version def _build_request(self, url: str, params): params = { **{"appID": self._app_id, "apiKey": self._app_key, "format": self._format}, **params, } payload = urlencode(params).encode("utf-8") def request(): with urlopen(url, payload) as response: return response.read().decode("utf-8") return request # Autogenerated method return the result of _{their name} method def _get_route_summary_for_stop(self, response) -> dict: return response # Autogenerate method that make API calls that enforce the correct arguements @make_oc_transport_request(transform_name=True, transform_args=True) def get_route_summary_for_stop( self, *, stop_no: int ) -> _get_route_summary_for_stop.__annotations__["return"]: pass def _get_next_trips_for_stop(self, response) -> dict: return response @make_oc_transport_request(transform_name=True, transform_args=True) def get_next_trips_for_stop( self, *, route_no: int, stop_no: int ) -> _get_next_trips_for_stop.__annotations__["return"]: pass def _get_next_trips_for_stop_all_routes(self, response) -> dict: return response @make_oc_transport_request(transform_name=True, transform_args=True) def get_next_trips_for_stop_all_routes( self, *, stop_no: int ) -> _get_next_trips_for_stop_all_routes.__annotations__["return"]: pass def _gtfs(self, response) -> dict: return response @make_oc_transport_request(transform_name=True, transform_args=False) def gtfs( self, *, table, id=None, column=None, value=None, order_by=None, direction=None, limit=None, ) -> _gtfs.__annotations__["return"]: pass PK!H_zTT+python_ottawa_transit-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]n0H*J>mlcAPK!H^.python_ottawa_transit-0.1.0.dist-info/METADATAT]o0} ݤ% Qj+HhCibiF"s?ε?1K3jiåyp@ƴd.𥵴Tn p?8EUT7L[4pa^ДBj fMIOcAW4GDasA*p^5~gtͳ#2aS<# !:sӎ`s곒" mP-fR08{ 7!!`rC_)-,s{LbkeeiYrÈ¢~$\>=2j, $J#?kϲ6DV!Q#` .'hmǩbuv[B*0iUb|uTdPY^p˙i祖z*q,0J l|0EC A+W>7@ר. 0i3]vnTx u~Yj]r}}=fIWXw ~κh[H9zb -K0ؽʸ.YܦvE2T-6ܑR=:4{.68g%n۹ x RImoᄊ}['83POxПœq{{L+ܷ}<9eޢ')1VK<~.3{W9g*n,s^sp(_ Lkф˖8vupG{C/:G1c9ȶ<pZv.UZłyuPK!H3,python_ottawa_transit-0.1.0.dist-info/RECORDKr0нgH"?]$MO% 0?p…xh*2YK5\6RquEL7ox$7[&b!ОtOᬓry7:ȶPѣu{!n xNu jV^Meslg'<݌~XkD7=xyMtR)98Ϋ!&8ďd#èJSLCv^TԵ_RlDđ @r^lnPK!fuu!python_ottawa_transit/__init__.pyPK!m` ` python_ottawa_transit/api.pyPK!H_zTT+Npython_ottawa_transit-0.1.0.dist-info/WHEELPK!H^.python_ottawa_transit-0.1.0.dist-info/METADATAPK!H3, python_ottawa_transit-0.1.0.dist-info/RECORDPKn