Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*- encoding:utf-8 -*-
- # Data : 26/08/2019
- # Api de previsão do tempo
- # Criado em Python3
- import requests
- import json
- accuweatherAPIKey = "xEXdIEMczxGxwrQIzfLrB5GY7J7hTuAG"
- re = requests.post('http://www.geoplugin.net/json.gp')
- if(re.status_code != 200):
- print('Não foi possivel obter a localização.')
- else:
- localizacao = json.loads(re.text)
- lat = localizacao['geoplugin_latitude']
- long = localizacao['geoplugin_longitude']
- LocationAPIUrl = "http://dataservice.accuweather.com/locations/v1/cities/geoposition/"\
- + "search?apikey=" + accuweatherAPIKey \
- + "&q=" + lat + "%2C" + long + "&language=pt-br"
- re2 = requests.get(LocationAPIUrl)
- if(re2.status_code != 200):
- print("Não foi possivel obter o código do local.")
- else:
- locationResponse = json.loads(re2.text)
- nomeLocal = locationResponse['LocalizedName'] + ", "\
- + locationResponse['AdministrativeArea']['LocalizedName'] + ", "\
- + locationResponse['Country']['LocalizedName']
- codigoLocal = locationResponse['Key']
- print("Obtendo clima do local", nomeLocal)
- CurrentConditionsAPIUrl =
Advertisement
Add Comment
Please, Sign In to add comment