From 6febb7a4b7a9c91556e575f0fac0ad42a596b782 Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Mon, 12 Aug 2024 01:10:29 -0700 Subject: [PATCH] Fix mypy errors in shuttle.py --- pittapi/shuttle.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pittapi/shuttle.py b/pittapi/shuttle.py index 54943fa..6d906ea 100644 --- a/pittapi/shuttle.py +++ b/pittapi/shuttle.py @@ -21,6 +21,8 @@ from typing import Any +JSON = dict[str, Any] + API_KEY = "8882812681" VEHICLE_POINTS_URL = "http://www.pittshuttle.com/Services/JSONPRelay.svc/GetMapVehiclePoints" ARRIVAL_TIMES_URL = "http://www.pittshuttle.com/Services/JSONPRelay.svc/GetRouteStopArrivals" @@ -30,29 +32,33 @@ sess = requests.session() -def get_map_vehicle_points(api_key: str = API_KEY) -> dict[str, Any]: +def get_map_vehicle_points(api_key: str = API_KEY) -> JSON: """Return the map location for all active vehicles.""" payload = {"ApiKey": api_key} response = sess.get(VEHICLE_POINTS_URL, params=payload) - return response.json() + response_json: JSON = response.json() + return response_json -def get_route_stop_arrivals(api_key: str = API_KEY, times_per_stop: int = 1) -> dict[str, Any]: +def get_route_stop_arrivals(api_key: str = API_KEY, times_per_stop: int = 1) -> JSON: """Return stop arrival times for all vehicles.""" - payload = {"ApiKey": api_key, "TimesPerStopString": times_per_stop} + payload = {"ApiKey": api_key, "TimesPerStopString": str(times_per_stop)} response = sess.get(ARRIVAL_TIMES_URL, params=payload) - return response.json() + response_json: JSON = response.json() + return response_json -def get_vehicle_route_stop_estimates(vehicle_id: str, quantity: int = 2) -> dict[str, Any]: +def get_vehicle_route_stop_estimates(vehicle_id: str, quantity: int = 2) -> JSON: """Return {quantity} stop estimates for all active vehicles.""" payload = {"vehicleIdStrings": vehicle_id, "quantity": str(quantity)} response = sess.get(STOP_ESTIMATES_URL, params=payload) - return response.json() + response_json: JSON = response.json() + return response_json -def get_routes(api_key: str = API_KEY) -> dict[str, Any]: +def get_routes(api_key: str = API_KEY) -> JSON: """Return the routes with Vehicle Route Name, Vehicle ID, and all stops, etc.""" payload = {"ApiKey": api_key} response = sess.get(ROUTES_URL, params=payload) - return response.json() + response_json: JSON = response.json() + return response_json