vinissh

weatherapp.py

Aug 27th, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. #-*- encoding:utf-8 -*-
  2.  
  3.  
  4. # Data : 26/08/2019
  5. # Api de previsão do tempo
  6. # Criado em Python3
  7.  
  8.  
  9. import requests
  10. import json
  11.  
  12. accuweatherAPIKey = "xEXdIEMczxGxwrQIzfLrB5GY7J7hTuAG"
  13.  
  14. re = requests.post('http://www.geoplugin.net/json.gp')
  15.  
  16. if(re.status_code != 200):
  17.     print('Não foi possivel obter a localização.')
  18. else:
  19.     localizacao = json.loads(re.text)
  20.     lat = localizacao['geoplugin_latitude']
  21.     long = localizacao['geoplugin_longitude']
  22.     LocationAPIUrl = "http://dataservice.accuweather.com/locations/v1/cities/geoposition/"\
  23.                      + "search?apikey=" + accuweatherAPIKey \
  24.                      + "&q=" + lat + "%2C" + long + "&language=pt-br"
  25.  
  26.  
  27.     re2 = requests.get(LocationAPIUrl)
  28.     if(re2.status_code != 200):
  29.         print("Não foi possivel obter o código do local.")
  30.     else:
  31.         locationResponse = json.loads(re2.text)
  32.         nomeLocal = locationResponse['LocalizedName'] + ", "\
  33.                     + locationResponse['AdministrativeArea']['LocalizedName'] + ", "\
  34.                     + locationResponse['Country']['LocalizedName']
  35.         codigoLocal = locationResponse['Key']
  36.         print("Obtendo clima do local", nomeLocal)
  37.  
  38.         CurrentConditionsAPIUrl =
Advertisement
Add Comment
Please, Sign In to add comment