B
B
Brad_baf2020-06-19 20:09:52
Python
Brad_baf, 2020-06-19 20:09:52

How to properly distribute information?

The code:

import requests

x = input("Введите название города: ")

appid = "APPid"

res = requests.get("http://api.openweathermap.org/data/2.5/forecast", params={
                   'q': x, 'units': 'metric', 'lang': 'ru', 'APPID': appid})
data = res.json()
for i in data['list']:
    a = f"{i['dt_txt'][5:10]}: \n"
    b = f"{i['dt_txt'][11:16]}: Температура: {'{0:+3.0f}'.format(i['main']['temp'])}, ветер: {'{0:1.0f}'.format(i['wind']['speed'])} м/с, описание: {i['weather'][0]['description']}"
    print(a+b)


I am parsing the weather, there is a code in which I get the following output:
06-19:
18:00: Temperature: +21, wind: 1 m / s, weather description: light rain
06-19:
21:00: Temperature: +18, wind: 1 m/s, weather description: light rain
06-20:
00:00: Temperature: +16, wind: 1 m/s, weather description: light rain
06-20:
03:00: Temperature: +16, wind: 1 m/s, weather description: light rain
06-20:
06:00: Temperature: +16, wind: 2 m/s, weather description: light rain
06-20:
09:00: Temperature: +17, wind: 3 m/s, weather description: light rain
06-20:
12:00: Temperature: +19, wind: 3 m/s, weather description: light rain
06-20:
15:00: Temperature: +20, wind: 4 m/s, weather description: light rain
06-20:
18:00: Temperature: +17, wind: 4 m/s, weather description: light rain
06-20:
21:00: Temperature: +16, wind: 3 m/s, weather description: light rain
06-21:
00:00: Temperature: +16, wind: 3 m/s, weather description: rain
06-21:
03 :00: Temperature: +16, wind: 3 m/s, weather description: light rain
06-21:
06:00: Temperature: +17, wind: 3 m/s, weather description: light rain
06-21:
09 :00: Temperature: +18, wind: 3 m/s, weather description: light rain
06-21:
12:00: Temperature: +22, wind: 3 m/s, weather description: light rain
06-21:
15:00: Temperature: +22, wind: 1 m/s, weather description: rain
06-21:
18:00: Temperature: +19, wind: 0 m/s, weather description: rain
06-21:
21: 00: Temperature: +17, wind: 2 m/s, weather description: light rain
06-22:
00:00: Temperature: +16, wind: 1 m/s, weather description: light rain
06-22:
03: 00: Temperature: +17, wind: 2 m/s, weather description: light rain
06-22:
06:00: Temperature: +19, wind: 2 m/s, weather description: overcast
06-22:
09:00 : Temperature: +20, wind: 3 m/s, weather description: light rain
06-22:
12:00: Temperature: +22, wind: 5 m/s, weather description: light rain
06-22:
15:00 : Temperature: +19, wind: 5 m/s, weather description: rain
06-22:
18:00: Temperature: +18, wind: 5 m/s, weather description: rain
06-22:
21:00: Temperature: +17, wind: 4 m/s, weather description: light rain
06 -23: 00:00:
Temperature: +17, wind: 4 m/s, weather description: light rain
06-23:
03:00: Temperature: +16, wind: 4 m/s, weather description: light rain
06 -23:
06:00: Temperature: +16, wind: 5 m/s, weather description: light rain
06-23:
09:00: Temperature: +13, wind: 4 m/s, weather description: light rain
06 -23:
12:00: Temperature: +15, wind: 4 m/s, weather description: light rain
06-23:
15:00: Temperature: +15, wind: 2 m/s, weather description: overcast
06- 23:
18:00: Temperature: +16, wind: 2 m/s, weather description: light rain
06-23:
21:00: Temperature: +13, wind: 3 m/s, weather description: light rain
06-24:
00:00: Temperature: +12, wind: 2 m/s, weather description: partly cloudy
06-24:
03:00: Temperature: +11, wind: 2 m/s, weather description: clear
06-24:
06 :00: Temperature: +15, wind: 2 m/s, weather description: partly cloudy
06-24:
09:00: Temperature: +18, wind: 3 m/s, weather description: light rain
06-24:
12 :00: Temperature: +19, wind: 3 m/s, weather description: light rain
06-24: 15:00
: Temperature: +19, wind: 3 m/s, weather description: light rain

the output was like this:
06-19:
18:00: Temperature: +21, wind: 1 m/s, weather description: light rain
21:00: Temperature: +18, wind: 1 m/s, weather description: light rain
06-20:
00:00: Temperature: +16, wind: 1 m/s, weather description: light rain
03:00: Temperature: +16, wind: 1 m/s, weather description: light rain
06:00: Temperature: +16 , wind: 2 m/s, weather description: light rain
09:00: Temperature: +17, wind: 3 m/s, weather description: light rain
12:00: Temperature: +19, wind: 3 m/s, weather description: light rain
15:00: temperature: +20, wind: 4 m/s, weather description: light rain
18:00: temperature: +17, wind: 4 m/s, weather description: light rain
21:00 : Temperature: +16, wind: 3 m/s, weather description: light rain

06-21:
00:00: Temperature: +16, wind: 3 m/s, weather description: rain
03:00: Temperature: +16, wind: 3 m/s, weather description: light rain
06:00: Temperature : +17, wind: 3 m/s, weather description: light rain
09:00: Temperature: +18, wind: 3 m/s, weather description: light rain
12:00: Temperature: +22, wind: 3 m /s, weather description: light rain
15:00: Temperature: +22, wind: 1 m/s, weather description: rain
18:00: Temperature: +19, wind: 0 m/s, weather description: rain
21: 00: Temperature: +17, wind: 2 m/s, weather description: light rain

06-22:
00:00: Temperature: +16, wind: 1 m/s, weather description: light rain
03:00: Temperature: +17, wind: 2 m/s, weather description: light rain
06:00: Temperature: +19, wind: 2 m/s, weather description: overcast
09:00: Temperature: +20, wind: 3 m/s, weather description: light rain
12:00: Temperature: +22, wind: 5 m/s, weather description: light rain
15:00: Temperature: +19, wind: 5 m/s, weather description: rain
18:00: Temperature: +18, wind: 5 m/s, weather description : rain
21:00: Temperature: +17, wind: 4 m/s, weather description: light rain

06-23:
00:00: Temperature: +17, wind: 4 m/s, weather description: light rain
03: 00: Temperature: +16, wind: 4 m/s, weather description: light rain
06:00: Temperature: +16, wind: 5 m/s, weather description: light rain
09:00: Temperature: +13, wind : 4 m/s, weather description: light rain
12:00: Temperature: +15, wind: 4 m/s, weather description: light rain
15:00: Temperature: +15, wind: 2 m/s, weather description: overcast
18:00: Temperature: +16, wind: 2 m/s, weather description: light rain
21:00: Temperature: +13, wind: 3 m/s, weather description: light rain

06-24:
00:00: Temperature: +12, wind: 2 m /s, weather description: partly cloudy
03:00: Temperature: +11, wind: 2 m/s, weather description: clear
06:00: Temperature: +15, wind: 2 m/s, weather description: partly cloudy
09 :00: Temperature: +18, wind: 3 m/s, weather description: light rain
12:00: Temperature: +19, wind: 3 m/s, weather description: light rain
15:00: Temperature: +19, wind: 3 m/s, weather description: light rain

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-19
@Brad_baf

An interesting conclusion you have. Is there really no correct output in the JSON result? why cut?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question