Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- cities = [
- 'Омск',
- 'Калининград',
- 'Челябинск',
- 'Владивосток',
- 'Красноярск',
- 'Москва',
- 'Екатеринбург'
- ]
- def make_url(city):
- return f'http://wttr.in/{city}'
- def make_parameters():
- params = {
- 'format': 2,
- 'M': ''
- }
- return params
- def what_weather(city):
- try:
- response = requests.get(make_url(city), make_parameters())
- except requests.ConnectionError:
- print('<сетевая ошибка>')
- code = response.status_code
- if code == 200:
- print(response.text)
- else:
- print('<ошибка на сервере погоды>')
- print('Погода в городах:')
- for city in cities:
- print(city, what_weather(city))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement