tuomasvaltanen

Untitled

Nov 10th, 2022 (edited)
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # koodipaja, 10.11.2022
  2. print("Tervetuloa!")
  3.  
  4. # UUSI TIEDOSTO
  5.  
  6. import json
  7. import urllib.request
  8.  
  9. url = "https://edu.frostbit.fi/api/weather/"
  10. req = urllib.request.Request(url)
  11. raw_data = urllib.request.urlopen(req).read().decode("UTF-8")
  12.  
  13. weather = json.loads(raw_data)
  14.  
  15. strongest_wind = 0
  16. strongest_wind_city = ""
  17. weakest_wind = 0
  18. weakest_wind_city = ""
  19.  
  20. for city in weather:
  21.     #print(city)
  22.     name = city['location']
  23.     wind = city['wind']
  24.     print(name)
  25.     print(wind)
  26.     print()
  27.  
  28.     # jos wind on suurempi kuin strongest_wind => silloin strongest_wind = wind
  29.     # samalla asetetaan talteen mikä oli se kaupunki, missä oli suurin tuuli, eli
  30.     # strongest_wind_city = name jne
  31.  
  32.     # jos tämän kaupungin tuuli on kovempi kuin strongest_wind
  33.     # => päivitetään strongest_wind
  34.  
Advertisement
Add Comment
Please, Sign In to add comment