-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestTotalFromAgromini.py
More file actions
79 lines (70 loc) · 2.36 KB
/
TestTotalFromAgromini.py
File metadata and controls
79 lines (70 loc) · 2.36 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
71
72
73
74
75
76
77
78
79
import requests
import time
from APIoperation import load_api_key
API_KEY = load_api_key() # API Key
BASE_URL = "http://api.agromonitoring.com/agro/1.0"
def create_polygon():
url = f"{BASE_URL}/polygons"
params = {"appid": API_KEY, "duplicated": "true"}
data = {
"name": "Limerick Test Polygon",
"geo_json": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-8.64006, 52.66994],
[-8.63806, 52.66994],
[-8.63806, 52.66894],
[-8.64006, 52.66894],
[-8.64006, 52.66994]
]
]
}
}
}
response = requests.post(url, params=params, json=data)
if response.status_code == 201:
polygon_id = response.json().get("id")
print(f"Polygon created with ID: {polygon_id}")
return polygon_id
else:
print(f"Error creating polygon: {response.status_code}")
print(response.text)
return None
def get_data(endpoint, polygon_id):
url = f"{BASE_URL}/{endpoint}"
params = {"polyid": polygon_id, "appid": API_KEY}
print(f"Requesting {url} with params: {params}")
response = requests.get(url, params=params)
if response.status_code == 200:
return response.json()
else:
print(f"Error fetching {endpoint} data: {response.status_code}")
print(response.text)
return None
def aggregate_data():
# polygon_id = create_polygon()
polygon_id = '677e653fc46b9f856bdfb3f0'
if not polygon_id:
print("Failed to create polygon. Exiting.")
return
soil_data = get_data("soil", polygon_id)
weather_data = get_data("weather", polygon_id)
historical_weather_data = get_data("weather/history", polygon_id)
ndvi_data = get_data("image/search", polygon_id)
aggregated_data = {
"polygon_id": polygon_id,
"soil_data": soil_data,
"current_weather": weather_data,
"historical_weather": historical_weather_data,
"ndvi_data": ndvi_data
}
print("\nAggregated Data:")
for key, value in aggregated_data.items():
print(f"{key}: {value}")
return aggregated_data
if __name__ == "__main__":
aggregate_data()