-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmbta_helper.py
More file actions
70 lines (49 loc) · 2.14 KB
/
mbta_helper.py
File metadata and controls
70 lines (49 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import json
import urllib.request
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Get API keys from environment variables
MAPBOX_TOKEN = os.getenv("MAPBOX_TOKEN")
MBTA_API_KEY = os.getenv("MBTA_API_KEY")
# Optional: helpful error messages if keys are missing
if MAPBOX_TOKEN is None:
raise RuntimeError("MAPBOX_TOKEN is not set. Check your .env file.")
if MBTA_API_KEY is None:
raise RuntimeError("MBTA_API_KEY is not set. Check your .env file.")
# Useful base URLs (you need to add the appropriate parameters for each API request)
MAPBOX_BASE_URL = "https://api.mapbox.com/search/searchbox/v1/forward"
MBTA_BASE_URL = "https://api-v3.mbta.com/"
# A little bit of scaffolding if you want to use it
def get_json(url: str) -> dict:
"""
Given a properly formatted URL for a JSON web API request, return a Python JSON object containing the response to that request.
Both get_lat_lng() and get_nearest_station() might need to use this function.
"""
pass
def get_lat_lng(place_name: str) -> tuple[str, str]:
"""
Given a place name or address, return a (latitude, longitude) tuple with the coordinates of the given place.
See https://docs.mapbox.com/api/search/search-box/#search-request for Mapbox Search API URL formatting requirements.
"""
pass
def get_nearest_station(latitude: str, longitude: str) -> tuple[str, bool]:
"""
Given latitude and longitude strings, return a (station_name, wheelchair_accessible) tuple for the nearest MBTA station to the given coordinates. wheelchair_accessible is True if the stop is marked as accessible, False otherwise.
See https://api-v3.mbta.com/docs/swagger/index.html#/Stop/ApiWeb_StopController_index for URL formatting requirements for the 'GET /stops' API.
"""
pass
def find_stop_near(place_name: str) -> tuple[str, bool]:
"""
Given a place name or address, return the nearest MBTA stop and whether it is wheelchair accessible.
This function might use all the functions above.
"""
pass
def main():
"""
You should test all the above functions here
"""
pass
if __name__ == "__main__":
main()