Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from requests import get
- from requests.exceptions import HTTPError
- id_cidade = '3477' # Cidade de São Paulo
- site = 'https://www.climatempo.com.br/json/myclimatempo/'\
- 'user/weatherNow?idlocale=' + str(id_cidade)
- headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'\
- 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36'}
- try:
- json_callback = get(url=site, headers=headers).json()
- except HTTPError as http_err:
- print(f'HTTP erro no site: {http_err}')
- if json_callback:
- try:
- temperatura = json_callback[0]['data'][0]['weather'][0]['temperature']
- print(f"Temperatura: {temperatura}")
- except Exception:
- print('Falha ao obter dados')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement