Skip to content

Commit ffee3eb

Browse files
authored
Update api.py
1 parent def7571 commit ffee3eb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pipeline/api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import requests
32

43
API_URL = "https://api.data.gov.sg/v1/transport/traffic-images"
@@ -9,6 +8,7 @@ def __init__(self, url="No API URL"):
98
self.timestamp = None
109
self.api_status = "Unverified"
1110
self.metadata = None
11+
self.camera_id_array = []
1212

1313
# Get API response
1414
response = requests.get(self.url)
@@ -24,6 +24,10 @@ def __init__(self, url="No API URL"):
2424
print(f"The API status is: {self.api_status}")
2525
print(f"The API was called at: {self.timestamp}")
2626

27+
for item in self.metadata["items"]:
28+
for camera in item["cameras"]:
29+
self.camera_id_array.append(camera["camera_id"])
30+
2731
def extract_image(self, camera_id):
2832
# Loop through the items and cameras to find the correct camera_id
2933
for item in self.metadata["items"]:
@@ -33,6 +37,17 @@ def extract_image(self, camera_id):
3337
# If camera ID is not found
3438
return f"Camera ID {camera_id} not found."
3539

40+
def extract_latlon(self, camera_id):
41+
for item in self.metadata["items"]:
42+
for camera in item["cameras"]:
43+
if camera["camera_id"] == str(camera_id):
44+
longitude = camera["location"]["longitude"]
45+
latitude = camera["location"]["latitude"]
46+
return longitude, latitude # Return both longitude and latitude as a tuple
47+
# If camera ID is not found
48+
return f"Camera ID {camera_id} not found."
49+
50+
3651

3752

3853

0 commit comments

Comments
 (0)