-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuaca.py
32 lines (28 loc) · 1.04 KB
/
cuaca.py
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
import requests
class Cuaca:
def __init__(self, local_path):
self.local_path = local_path
self.provinces = [
"DKIJakarta",
"DIYogyakarta",
"JawaBarat",
"Bali",
"KalimantanSelatan",
]
self.prefix_url = "https://ibnux.github.io/BMKG-importer"
self.wilayah_url = f"{self.prefix_url}/cuaca/wilayah.json"
self.wilayah_data = []
self.wilayah_id_map = {}
self.weather_data = []
def get_wilayah_data(self) -> dict:
response = requests.get(self.wilayah_url)
self.wilayah_data = response.json()
for wilayah in self.wilayah_data:
key = (wilayah["propinsi"], wilayah["kota"])
if key[0] in self.provinces:
self.wilayah_id_map[key] = wilayah["id"]
return self.wilayah_id_map
def get_cuaca_by_id(self, id: int) -> list:
response = requests.get(f"{self.prefix_url}/cuaca/{id}.json")
self.weather_data = response.json()
return self.weather_data