Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import requests
  2.  
  3. cities = [
  4. 'Омск',
  5. 'Калининград',
  6. 'Челябинск',
  7. 'Владивосток',
  8. 'Красноярск',
  9. 'Москва',
  10. 'Екатеринбург'
  11. ]
  12.  
  13.  
  14. def make_url(city):
  15. return f'http://wttr.in/{city}'
  16.  
  17.  
  18. def make_parameters():
  19. params = {
  20. 'format': 2,
  21. 'M': ''
  22. }
  23. return params
  24.  
  25.  
  26. def what_weather(city):
  27. try:
  28. response = requests.get(make_url(city), make_parameters())
  29. except requests.ConnectionError:
  30. print('<сетевая ошибка>')
  31.  
  32. code = response.status_code
  33. if code == 200:
  34. print(response.text)
  35. else:
  36. print('<ошибка на сервере погоды>')
  37.  
  38.  
  39. print('Погода в городах:')
  40. for city in cities:
  41. print(city, what_weather(city))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement