This is my python code
import requests
response = requests.get('https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m,relativehumidity_2m,windspeed_10m')
print(response.content)
I got this result
b'{"latitude":52.52,"longitude":13.419998,"generationtime_ms":0.48100948333740234,"utc_offset_seconds":0,"timezone":"GMT","timezone_abbreviation":"GMT","elevation":38.0,"hourly_units":{"time":"iso8601","temperature_2m":"\xc2\xb0C","relativehumidity_2m":"%","windspeed_10m":"km/h"},"hourly":{"time":["2022-09-26T00:00","2022-09-26T01:00","2022-09-26T02:00","2022-09-26T03:00","2022-09-26T04:00","2022-09-26T05:00","2022-09-26T06:00","2022-09-26T07:00","2022-09-26T08:00","2022-09-26T09:00","2022-09-26T10:00","2022-09-26T11:00","2022-09-26T12:00","2022-09-26T13:00","2022-09-26T14:00","2022-09-26T15:00","2022-09-26T16:00","2022-09-26T17:00","2022-09-26T18:00","2022-09-26T19:00","2022-09-26T20:00","2022-09-26T21:00","2022-09-26T22:00","2022-09-26T23:00","2022-09-27T00:00","2022-09-27T01:00","2022-09-27T02:00","2022-09-27T03:00","2022-09-27T04:00","2022-09-27T05:00","2022-09-27T06:00","2022-09-27T07:00","2022-09-27T08:00","2022-09-27T09:00","2022-09-27T10:00","2022-09-27T11:00","2022-09-27T12:00","2022-09-27T13:00","2022-09-27T14:00","2022-09-27T15:00","2022-09-27T16:00","2022-09-27T17:00","2022-09-27T18:00","2022-09-27T19:00","2022-09-27T20:00","2022-09-27T21:00","2022-09-27T22:00","2022-09-27T23:00","2022-09-28T00:00","2022-09-28T01:00","2022-09-28T02:00","2022-09-28T03:00","2022-09-28T04:00","2022-09-28T05:00","2022-09-28T06:00","2022-09-28T07:00","2022-09-28T08:00","2022-09-28T09:00","2022-09-28T10:00","2022-09-28T11:00","2022-09-28T12:00","2022-09-28T13:00","2022-09-28T14:00","2022-09-28T15:00","2022-09-28T16:00","2022-09-28T17:00","2022-09-28T18:00","2022-09-28T19:00","2022-09-28T20:00","2022-09-28T21:00","2022-09-28T22:00","2022-09-28T23:00","2022-09-29T00:00","2022-09-29T01:00","2022-09-29T02:00","2022-09-29T03:00","2022-09-29T04:00","2022-09-29T05:00","2022-09-29T06:00","2022-09-29T07:00","2022-09-29T08:00","2022-09-29T09:00","2022-09-29T10:00","2022-09-29T11:00","2022-09-29T12:00","2022-09-29T13:00","2022-09-29T14:00","2022-09-29T15:00","2022-09-29T16:00","2022-09-29T17:00","2022-09-29T18:00","2022-09-29T19:00","2022-09-29T20:00","2022-09-29T21:00","2022-09-29T22:00","2022-09-29T23:00","2022-09-30T00:00","2022-09-30T01:00","2022-09-30T02:00","2022-09-30T03:00","2022-09-30T04:00","2022-09-30T05:00","2022-09-30T06:00","2022-09-30T07:00","2022-09-30T08:00","2022-09-30T09:00","2022-09-30T10:00","2022-09-30T11:00","2022-09-30T12:00","2022-09-30T13:00","2022-09-30T14:00","2022-09-30T15:00","2022-09-30T16:00","2022-09-30T17:00","2022-09-30T18:00","2022-09-30T19:00","2022-09-30T20:00","2022-09-30T21:00","2022-09-30T22:00","2022-09-30T23:00","2022-10-01T00:00","2022-10-01T01:00","2022-10-01T02:00","2022-10-01T03:00","2022-10-01T04:00","2022-10-01T05:00","2022-10-01T06:00","2022-10-01T07:00","2022-10-01T08:00","2022-10-01T09:00","2022-10-01T10:00","2022-10-01T11:00","2022-10-01T12:00","2022-10-01T13:00","2022-10-01T14:00","2022-10-01T15:00","2022-10-01T16:00","2022-10-01T17:00","2022-10-01T18:00","2022-10-01T19:00","2022-10-01T20:00","2022-10-01T21:00","2022-10-01T22:00","2022-10-01T23:00","2022-10-02T00:00","2022-10-02T01:00","2022-10-02T02:00","2022-10-02T03:00","2022-10-02T04:00","2022-10-02T05:00","2022-10-02T06:00","2022-10-02T07:00","2022-10-02T08:00","2022-10-02T09:00","2022-10-02T10:00","2022-10-02T11:00","2022-10-02T12:00","2022-10-02T13:00","2022-10-02T14:00","2022-10-02T15:00","2022-10-02T16:00","2022-10-02T17:00","2022-10-02T18:00","2022-10-02T19:00","2022-10-02T20:00","2022-10-02T21:00","2022-10-02T22:00","2022-10-02T23:00"],"temperature_2m":[11.7,11.4,11.0,10.7,10.0,9.7,10.2,11.3,13.0,14.6,15.8,17.0,17.0,17.4,17.3,16.8,16.3,15.5,14.4,13.5,12.9,12.7,12.4,12.0,11.7,11.6,11.5,11.4,11.2,10.9,10.7,11.0,11.4,12.2,12.8,12.9,12.1,12.6,12.7,12.0,11.4,11.0,10.1,9.7,9.4,9.2,8.9,8.4,8.0,7.8,7.9,8.1,8.0,8.0,7.8,8.1,9.3,10.5,11.2,11.2,11.2,10.8,10.4,10.5,10.8,10.1,9.3,8.7,8.0,7.2,6.2,5.9,5.7,5.3,4.9,4.6,4.6,4.4,4.7,6.4,8.8,10.9,12.7,13.6,13.9,14.4,14.4,14.0,13.6,12.6,11.1,10.3,9.6,8.7,8.1,7.6,7.1,6.8,6.6,6.3,6.0,5.7,6.0,7.5,9.6,12.2,13.6,14.7,15.8,16.2,16.3,16.0,15.2,14.1,12.6,11.8,11.1,10.2,9.7,9.3,8.7,8.3,7.8,7.3,6.8,6.3,6.6,8.1,10.3,13.0,14.5,15.8,17.0,16.7,15.7,14.3,13.6,13.0,12.4,12.0,11.6,11.3,11.3,11.4,11.5,11.5,11.5,11.4,11.3,11.1,11.1,11.7,12.6,13.4,13.2,12.6,12.2,12.6,13.3,14.0,14.0,13.7,13.3,12.9,12.6,12.1,11.9,11.8],"relativehumidity_2m":[88.0,90.0,90.0,90.0,93.0,95.0,93.0,84.0,74.0,67.0,53.0,45.0,47.0,47.0,44.0,47.0,47.0,52.0,58.0,65.0,68.0,74.0,73.0,75.0,76.0,76.0,75.0,76.0,78.0,81.0,85.0,85.0,83.0,77.0,75.0,70.0,77.0,74.0,75.0,74.0,78.0,77.0,81.0,87.0,86.0,83.0,89.0,93.0,94.0,93.0,94.0,94.0,94.0,92.0,89.0,85.0,77.0,69.0,63.0,64.0,63.0,69.0,73.0,73.0,69.0,74.0,78.0,80.0,83.0,87.0,92.0,92.0,93.0,94.0,94.0,94.0,94.0,93.0,92.0,84.0,76.0,69.0,61.0,53.0,52.0,50.0,51.0,54.0,55.0,59.0,68.0,73.0,78.0,83.0,85.0,87.0,88.0,89.0,90.0,90.0,91.0,91.0,89.0,83.0,74.0,63.0,57.0,53.0,48.0,46.0,44.0,45.0,49.0,55.0,62.0,65.0,68.0,71.0,73.0,74.0,76.0,78.0,79.0,81.0,83.0,84.0,83.0,77.0,69.0,59.0,55.0,53.0,51.0,52.0,57.0,64.0,69.0,74.0,80.0,83.0,86.0,88.0,88.0,88.0,87.0,87.0,86.0,86.0,86.0,87.0,86.0,82.0,77.0,73.0,77.0,83.0,90.0,89.0,87.0,83.0,82.0,82.0,82.0,81.0,80.0,80.0,80.0,81.0],"windspeed_10m":[9.7,8.2,6.6,5.1,5.1,5.1,5.4,7.8,10.2,11.9,11.8,13.5,13.4,13.8,14.6,17.1,12.1,11.4,10.4,10.6,10.5,9.8,9.7,9.1,10.0,11.0,11.9,13.2,11.9,12.3,12.3,12.5,12.4,15.2,14.4,14.8,15.4,13.2,15.9,13.9,14.0,14.4,7.2,5.5,6.6,7.5,7.3,6.3,5.2,4.5,5.2,5.4,5.5,6.5,6.0,7.3,7.2,7.9,8.4,9.1,8.2,9.2,5.1,3.3,5.2,2.5,1.5,1.1,0.7,3.3,3.1,3.4,3.1,3.2,3.6,3.7,3.7,3.7,3.8,4.0,5.1,6.2,8.1,10.1,11.4,10.8,11.8,10.6,8.7,5.4,6.7,6.5,6.2,6.1,6.1,5.9,5.6,5.7,5.5,5.6,5.3,4.7,4.6,5.1,5.6,6.9,8.2,9.3,10.5,10.6,10.0,8.7,7.1,5.1,4.1,4.7,5.4,6.5,6.9,6.8,6.8,6.5,6.2,5.7,5.5,5.8,6.0,6.5,7.4,8.3,9.7,12.7,16.1,16.7,16.3,15.0,14.5,13.9,13.0,12.7,12.7,12.9,12.7,12.6,12.3,12.9,13.8,14.5,14.0,13.0,12.1,11.9,12.2,12.8,12.9,12.3,11.7,10.4,10.5,12.2,13.7,15.1,16.6,17.0,17.5,17.3,16.5,15.7]}}'
I want to get this result
{
"latitude": 52.52,
"longitude": 13.419998,
"generationtime_ms": 0.47206878662109375,
"utc_offset_seconds": 0,
"timezone": "GMT",
"timezone_abbreviation": "GMT",
"elevation": 38,
"hourly_units": {
"time": "iso8601",
"temperature_2m": "°C",
"relativehumidity_2m": "%",
"windspeed_10m": "km/h"
},
}
I have no idea how to get this result. Someone help me? Thanks for your help.
CodePudding user response:
This is what you need. It format the content to JSON format.
import requests
response = requests.get('https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m,relativehumidity_2m,windspeed_10m')
print(response.json())
CodePudding user response:
You need to use response.json().
import requests
import json
response = requests.get('https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m,relativehumidity_2m,windspeed_10m')
print(json.dumps(response.json(), indent=4))
and the output will be json formatted and you can do whatever you want with it after:
{
"latitude":52.52,
"longitude":13.419998,
"generationtime_ms":0.41306018829345703,
"utc_offset_seconds":0,
"timezone":"GMT",
"timezone_abbreviation":"GMT",
"elevation":38.0,
"hourly_units":{
"time":"iso8601",
"temperature_2m":"°C",
"relativehumidity_2m":"%",
"windspeed_10m":"km/h"
},
"hourly":{
"time":[
"2022-09-26T00:00",
"2022-09-26T01:00",
"2022-09-26T02:00",
"2022-09-26T03:00",
"2022-09-26T04:00",
"2022-09-26T05:00",
"2022-09-26T06:00",
"2022-09-26T07:00",
"2022-09-26T08:00",
"2022-09-26T09:00",
"2022-09-26T10:00",
"2022-09-26T11:00",
"2022-09-26T12:00",
"2022-09-26T13:00",
"2022-09-26T14:00",
"2022-09-26T15:00",
"2022-09-26T16:00",
"2022-09-26T17:00",
"2022-09-26T18:00",
"2022-09-26T19:00",
"2022-09-26T20:00",
"2022-09-26T21:00",
"2022-09-26T22:00",
"2022-09-26T23:00",
"2022-09-27T00:00",
"2022-09-27T01:00",
"2022-09-27T02:00",
"2022-09-27T03:00",
"2022-09-27T04:00",
"2022-09-27T05:00",
"2022-09-27T06:00",
"2022-09-27T07:00",
"2022-09-27T08:00",
"2022-09-27T09:00",
"2022-09-27T10:00",
"2022-09-27T11:00",
"2022-09-27T12:00",
"2022-09-27T13:00",
"2022-09-27T14:00",
"2022-09-27T15:00",
"2022-09-27T16:00",
"2022-09-27T17:00",
"2022-09-27T18:00",
"2022-09-27T19:00",
"2022-09-27T20:00",
"2022-09-27T21:00",
"2022-09-27T22:00",
"2022-09-27T23:00",
"2022-09-28T00:00",
"2022-09-28T01:00",
"2022-09-28T02:00",
"2022-09-28T03:00",
"2022-09-28T04:00",
"2022-09-28T05:00",
"2022-09-28T06:00",
"2022-09-28T07:00",
"2022-09-28T08:00",
"2022-09-28T09:00",
"2022-09-28T10:00",
"2022-09-28T11:00",
"2022-09-28T12:00",
"2022-09-28T13:00",
"2022-09-28T14:00",
"2022-09-28T15:00",
"2022-09-28T16:00",
"2022-09-28T17:00",
"2022-09-28T18:00",
"2022-09-28T19:00",
"2022-09-28T20:00",
"2022-09-28T21:00",
"2022-09-28T22:00",
"2022-09-28T23:00",
"2022-09-29T00:00",
"2022-09-29T01:00",
"2022-09-29T02:00",
"2022-09-29T03:00",
"2022-09-29T04:00",
"2022-09-29T05:00",
"2022-09-29T06:00",
"2022-09-29T07:00",
"2022-09-29T08:00",
"2022-09-29T09:00",
"2022-09-29T10:00",
"2022-09-29T11:00",
"2022-09-29T12:00",
"2022-09-29T13:00",
"2022-09-29T14:00",
"2022-09-29T15:00",
"2022-09-29T16:00",
"2022-09-29T17:00",
"2022-09-29T18:00",
"2022-09-29T19:00",
"2022-09-29T20:00",
"2022-09-29T21:00",
"2022-09-29T22:00",
"2022-09-29T23:00",
"2022-09-30T00:00",
"2022-09-30T01:00",
"2022-09-30T02:00",
"2022-09-30T03:00",
"2022-09-30T04:00",
"2022-09-30T05:00",
"2022-09-30T06:00",
"2022-09-30T07:00",
"2022-09-30T08:00",
"2022-09-30T09:00",
"2022-09-30T10:00",
"2022-09-30T11:00",
"2022-09-30T12:00",
"2022-09-30T13:00",
"2022-09-30T14:00",
"2022-09-30T15:00",
"2022-09-30T16:00",
"2022-09-30T17:00",
"2022-09-30T18:00",
"2022-09-30T19:00",
"2022-09-30T20:00",
"2022-09-30T21:00",
"2022-09-30T22:00",
"2022-09-30T23:00",
"2022-10-01T00:00",
"2022-10-01T01:00",
"2022-10-01T02:00",
"2022-10-01T03:00",
"2022-10-01T04:00",
"2022-10-01T05:00",
"2022-10-01T06:00",
"2022-10-01T07:00",
"2022-10-01T08:00",
"2022-10-01T09:00",
"2022-10-01T10:00",
"2022-10-01T11:00",
"2022-10-01T12:00",
"2022-10-01T13:00",
"2022-10-01T14:00",
"2022-10-01T15:00",
"2022-10-01T16:00",
"2022-10-01T17:00",
"2022-10-01T18:00",
"2022-10-01T19:00",
"2022-10-01T20:00",
"2022-10-01T21:00",
"2022-10-01T22:00",
"2022-10-01T23:00",
"2022-10-02T00:00",
"2022-10-02T01:00",
"2022-10-02T02:00",
"2022-10-02T03:00",
"2022-10-02T04:00",
"2022-10-02T05:00",
"2022-10-02T06:00",
"2022-10-02T07:00",
"2022-10-02T08:00",
"2022-10-02T09:00",
"2022-10-02T10:00",
"2022-10-02T11:00",
"2022-10-02T12:00",
"2022-10-02T13:00",
"2022-10-02T14:00",
"2022-10-02T15:00",
"2022-10-02T16:00",
"2022-10-02T17:00",
"2022-10-02T18:00",
"2022-10-02T19:00",
"2022-10-02T20:00",
"2022-10-02T21:00",
"2022-10-02T22:00",
"2022-10-02T23:00"
],
"temperature_2m":[
11.7,
11.4,
11.0,
10.7,
10.0,
9.7,
10.2,
11.3,
13.0,
14.6,
15.8,
17.0,
17.0,
17.4,
17.3,
16.8,
16.3,
15.5,
14.4,
13.5,
12.9,
12.7,
12.4,
12.0,
11.7,
11.6,
11.5,
11.4,
11.2,
10.9,
10.7,
11.0,
11.4,
12.2,
12.8,
12.9,
12.1,
12.6,
12.7,
12.0,
11.4,
11.0,
10.1,
9.7,
9.4,
9.2,
8.9,
8.4,
8.0,
7.8,
7.9,
8.1,
8.0,
8.0,
7.8,
8.1,
9.3,
10.5,
11.2,
11.2,
11.2,
10.8,
10.4,
10.5,
10.8,
10.1,
9.3,
8.7,
8.0,
7.2,
6.2,
5.9,
5.7,
5.3,
4.9,
4.6,
4.6,
4.4,
4.7,
6.4,
8.8,
10.9,
12.7,
13.6,
13.9,
14.4,
14.4,
14.0,
13.6,
12.6,
11.1,
10.3,
9.6,
8.7,
8.1,
7.6,
7.1,
6.8,
6.6,
6.3,
6.0,
5.7,
6.0,
7.5,
9.6,
12.2,
13.6,
14.7,
15.8,
16.2,
16.3,
16.0,
15.2,
14.1,
12.6,
11.8,
11.1,
10.2,
9.7,
9.3,
8.7,
8.3,
7.8,
7.3,
6.8,
6.3,
6.6,
8.1,
10.3,
13.0,
14.5,
15.8,
17.0,
16.7,
15.7,
14.3,
13.6,
13.0,
12.4,
12.0,
11.6,
11.3,
11.3,
11.4,
11.5,
11.5,
11.5,
11.4,
11.3,
11.1,
11.1,
11.7,
12.6,
13.4,
13.2,
12.6,
12.2,
12.6,
13.3,
14.0,
14.0,
13.7,
13.3,
12.9,
12.6,
12.1,
11.9,
11.8
],
"relativehumidity_2m":[
88.0,
90.0,
90.0,
90.0,
93.0,
95.0,
93.0,
84.0,
74.0,
67.0,
53.0,
45.0,
47.0,
47.0,
44.0,
47.0,
47.0,
52.0,
58.0,
65.0,
68.0,
74.0,
73.0,
75.0,
76.0,
76.0,
75.0,
76.0,
78.0,
81.0,
85.0,
85.0,
83.0,
77.0,
75.0,
70.0,
77.0,
74.0,
75.0,
74.0,
78.0,
77.0,
81.0,
87.0,
86.0,
83.0,
89.0,
93.0,
94.0,
93.0,
94.0,
94.0,
94.0,
92.0,
89.0,
85.0,
77.0,
69.0,
63.0,
64.0,
63.0,
69.0,
73.0,
73.0,
69.0,
74.0,
78.0,
80.0,
83.0,
87.0,
92.0,
92.0,
93.0,
94.0,
94.0,
94.0,
94.0,
93.0,
92.0,
84.0,
76.0,
69.0,
61.0,
53.0,
52.0,
50.0,
51.0,
54.0,
55.0,
59.0,
68.0,
73.0,
78.0,
83.0,
85.0,
87.0,
88.0,
89.0,
90.0,
90.0,
91.0,
91.0,
89.0,
83.0,
74.0,
63.0,
57.0,
53.0,
48.0,
46.0,
44.0,
45.0,
49.0,
55.0,
62.0,
65.0,
68.0,
71.0,
73.0,
74.0,
76.0,
78.0,
79.0,
81.0,
83.0,
84.0,
83.0,
77.0,
69.0,
59.0,
55.0,
53.0,
51.0,
52.0,
57.0,
64.0,
69.0,
74.0,
80.0,
83.0,
86.0,
88.0,
88.0,
88.0,
87.0,
87.0,
86.0,
86.0,
86.0,
87.0,
86.0,
82.0,
77.0,
73.0,
77.0,
83.0,
90.0,
89.0,
87.0,
83.0,
82.0,
82.0,
82.0,
81.0,
80.0,
80.0,
80.0,
81.0
],
"windspeed_10m":[
9.7,
8.2,
6.6,
5.1,
5.1,
5.1,
5.4,
7.8,
10.2,
11.9,
11.8,
13.5,
13.4,
13.8,
14.6,
17.1,
12.1,
11.4,
10.4,
10.6,
10.5,
9.8,
9.7,
9.1,
10.0,
11.0,
11.9,
13.2,
11.9,
12.3,
12.3,
12.5,
12.4,
15.2,
14.4,
14.8,
15.4,
13.2,
15.9,
13.9,
14.0,
14.4,
7.2,
5.5,
6.6,
7.5,
7.3,
6.3,
5.2,
4.5,
5.2,
5.4,
5.5,
6.5,
6.0,
7.3,
7.2,
7.9,
8.4,
9.1,
8.2,
9.2,
5.1,
3.3,
5.2,
2.5,
1.5,
1.1,
0.7,
3.3,
3.1,
3.4,
3.1,
3.2,
3.6,
3.7,
3.7,
3.7,
3.8,
4.0,
5.1,
6.2,
8.1,
10.1,
11.4,
10.8,
11.8,
10.6,
8.7,
5.4,
6.7,
6.5,
6.2,
6.1,
6.1,
5.9,
5.6,
5.7,
5.5,
5.6,
5.3,
4.7,
4.6,
5.1,
5.6,
6.9,
8.2,
9.3,
10.5,
10.6,
10.0,
8.7,
7.1,
5.1,
4.1,
4.7,
5.4,
6.5,
6.9,
6.8,
6.8,
6.5,
6.2,
5.7,
5.5,
5.8,
6.0,
6.5,
7.4,
8.3,
9.7,
12.7,
16.1,
16.7,
16.3,
15.0,
14.5,
13.9,
13.0,
12.7,
12.7,
12.9,
12.7,
12.6,
12.3,
12.9,
13.8,
14.5,
14.0,
13.0,
12.1,
11.9,
12.2,
12.8,
12.9,
12.3,
11.7,
10.4,
10.5,
12.2,
13.7,
15.1,
16.6,
17.0,
17.5,
17.3,
16.5,
15.7
]
}
}