Diomedes Git
commited on
Commit
·
4daf3d7
1
Parent(s):
0488605
added some new tools for crow to use(observation), moon/sun, air quality, edited entrypoint to reflect. also edited news search to better implement cascade pattern
Browse files
src/utils/air_monitoring_location_finder.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Load the .env file
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
def find_nearby_stations(latitude, longitude, radius=10000):
|
| 9 |
+
url = "https://api.openaq.org/v3/locations"
|
| 10 |
+
params = {
|
| 11 |
+
'coordinates': f"{latitude},{longitude}",
|
| 12 |
+
'radius': radius,
|
| 13 |
+
'limit': 10,
|
| 14 |
+
'sort': 'distance' # Changed from 'order_by' to 'sort'
|
| 15 |
+
}
|
| 16 |
+
headers = {
|
| 17 |
+
'Accept': 'application/json',
|
| 18 |
+
'X-API-Key': os.getenv("OPEN_AQ_KEY") # Include your API key
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
response = requests.get(url, params=params, headers=headers)
|
| 22 |
+
|
| 23 |
+
if response.status_code == 200:
|
| 24 |
+
return response.json().get('results', [])
|
| 25 |
+
else:
|
| 26 |
+
print(f"Error: {response.status_code}, {response.text}")
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
# NY coordinate
|
| 30 |
+
# latitude = 40.7042166653089
|
| 31 |
+
# longitude = -73.98696415012104
|
| 32 |
+
|
| 33 |
+
# # GLA
|
| 34 |
+
# latitude = 55.86588687325689
|
| 35 |
+
# longitude = -4.243144022737119
|
| 36 |
+
|
| 37 |
+
# # seattle
|
| 38 |
+
# latitude = 47.61736470806638
|
| 39 |
+
# longitude = -122.31305640979505
|
| 40 |
+
|
| 41 |
+
# tokyo
|
| 42 |
+
latitude = 35.66077151981672
|
| 43 |
+
longitude = 139.42421731458725
|
| 44 |
+
|
| 45 |
+
# Find nearby stations
|
| 46 |
+
stations = find_nearby_stations(latitude, longitude, radius=2500)
|
| 47 |
+
|
| 48 |
+
if stations:
|
| 49 |
+
print("Nearby monitoring stations:")
|
| 50 |
+
for station in stations:
|
| 51 |
+
print(f"ID: {station['id']}, Name: {station['name']}, Distance: {station['distance']}m")
|
| 52 |
+
else:
|
| 53 |
+
print("No stations found nearby.")
|