-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
62 lines (52 loc) · 2.25 KB
/
main.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
58
59
60
61
62
import logging
import asyncio
import meteoblue_dataset_sdk
async def myFunction():
# query1 = {"units": {"temperature": "C", "velocity": "km/h", "length": "metric", "energy": "watts"}, "geometry": {"type": "Polygon", "coordinates": [[[2.96894, 46.041886], [2.96894, 48.216537], [10.989692, 48.216537], [10.989692, 46.041886], [2.96894, 46.041886]]]}, "format": "json", "timeIntervals": [
# "2017-01-01T+00:00/2019-01-31T+00:00"], "timeIntervalsAlignment": "none", "queries": [{"domain": "NEMSGLOBAL", "gapFillDomain": None, "timeResolution": "hourly", "codes": [{"code": 11, "level": "2 m above gnd"}], "transformations": [{"type": "aggregateTimeInterval", "aggregation": "mean"}, {"type": "spatialTotalAggregate", "aggregation": "mean"}]}]}
query = {
"units": {
"temperature": "C",
"velocity": "km/h",
"length": "metric",
"energy": "watts",
},
"geometry": {
"type": "MultiPoint",
"coordinates": [[7.57327, 47.558399, 279]],
"locationNames": ["Basel"],
},
"format": "json",
"timeIntervals": ["2019-01-01T+00:00/2019-01-01T+00:00"],
"timeIntervalsAlignment": "none",
"queries": [
{
"domain": "NEMSGLOBAL",
"gapFillDomain": None,
"timeResolution": "hourly",
"codes": [{"code": 11, "level": "2 m above gnd"}],
}
],
}
client = meteoblue_dataset_sdk.Client(apikey="xxxxxx") # ask for key
result = await client.query(query)
# result is a structured object containing timestamps and data
timeInterval = result.geometries[0].timeIntervals[0]
data = result.geometries[0].codes[0].timeIntervals[0].data
print(timeInterval)
# start: 1546300800
# end: 1546387200
# stride: 3600
print(data)
# [2.89, 2.69, 2.549999, 2.3800001,
# query1 = asyncio.create_task(mb.query(qparams))
# query2 = asyncio.create_task(mb.query(qparams))
# res1 = await query1
# res2 = await query2
# async with mb.query(query1) as response:
# json = await response.json()
# print(json)
# print(res1)
# print(res2)
logging.basicConfig(level=logging.DEBUG)
asyncio.run(myFunction())