-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
57 lines (49 loc) · 1.78 KB
/
data.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
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
import json
import plotly.io as pio
import plotly.express as px
import requests
pio.renderers.default = "iframe"
def _get_years() -> list[int]:
request = {
"query": [
{"code": "Jahr", "selection": {"filter": "top", "values": ["5"]}},
{
"code": "Sorte | Gemeinde",
"selection": {"filter": "item", "values": ["0"]},
},
],
"response": {"format": "json"},
}
response = requests.get(
"https://etab.llv.li/PXWEb/api/v1/de/eTab//Wirtschaftsbereiche%20und%20Unternehmen/Landwirtschaft/Landwirtschaftliche%20Erzeugnisse/361.203d.px",
json=request,
)
data = response.json()
return data["variables"][0]["valueTexts"]
def _get_liters_per_year(time_range: int) -> list[int]:
request = {
"query": [
{"code": "Jahr", "selection": {"filter": "top", "values": [time_range]}},
{
"code": "Sorte | Gemeinde",
"selection": {"filter": "item", "values": ["0"]},
},
],
"response": {"format": "json"},
}
response = requests.post(
"https://etab.llv.li/PXWEb/api/v1/de/eTab//Wirtschaftsbereiche%20und%20Unternehmen/Landwirtschaft/Landwirtschaftliche%20Erzeugnisse/361.203d.px",
json=request,
)
decoded_data = response.text.encode().decode("utf-8-sig")
response_dict = json.loads(decoded_data)
values = []
for year in response_dict["data"]:
values.append(int(year["values"][0]))
return values
def main() -> None:
years = _get_years()
liters_per_year = _get_liters_per_year(len(years))
data = {"years": years, "amount_in_liter": liters_per_year}
fig = px.line(data, x="years", y="amount_in_liter", title="Weinernte Lichtenstein")
fig.show()