Skip to content

Instantly share code, notes, and snippets.

@Wanhenri
Last active February 14, 2020 12:50
Show Gist options
  • Save Wanhenri/3bb7c323dc99437e5f6b818133811ee8 to your computer and use it in GitHub Desktop.
Save Wanhenri/3bb7c323dc99437e5f6b818133811ee8 to your computer and use it in GitHub Desktop.
API SOMAR
import requests
import json
Cidade = 'RiodeJaneiro-RJ'
DiasPrevisao = '7'
#response = requests.get('https://nimbus.somar.io/forecast/7days?city=SaoPaulo-SP&reference=Somar',headers={'x-api-key':'********'}).json()
response_forecast = requests.get('https://nimbus.somar.io/forecast/'+DiasPrevisao+'days?city='+ Cidade +'&reference=Somar',headers={'x-api-key':'*******'})
#print(json.dumps(response))
json_res_forecast = response_forecast.json()
metadata = str(json_res_forecast['days'])
#unit_type = '°F' if json_res['flags']['units'] == 'us' else '°C'
days = str(json_res_forecast['days'])
location = str(json_res_forecast['points']['location'])
city = str(json_res_forecast['points']['location']['ref'])
lat = str(json_res_forecast['points']['location']['latitude'])
lon = str(json_res_forecast['points']['location']['longitude'])
temperature_daily_min = str(json_res_forecast['points']['forecast']['temperature_daily_min'])
temperature_daily_max = str(json_res_forecast['points']['forecast']['temperature_daily_max'])
rel_humidity_daily_avg = str(json_res_forecast['points']['forecast']['rel_humidity_daily_avg'])
print("\n")
print("days",days)
#print("location",location)
print("city",city)
print("lat",lat)
print("lon",lon)
print("\n")
print("forecast")
print("\n")
print("temperature_daily_min",temperature_daily_min)
print("temperature_daily_max",temperature_daily_max)
print("rel_humidity_daily_avg",rel_humidity_daily_avg)
response_observer = requests.get('https://nimbus.somar.io/observed/daily?city='+ Cidade +'&reference=Somar&days='+DiasPrevisao+'',headers={'x-api-key':'********'})
json_res_observer = response_observer.json()
max_temperature = str(json_res_observer['points']['observed']['max_temperature'])
min_temperature = str(json_res_observer['points']['observed']['min_temperature'])
#rel_humidity_daily_avg_obs =
max_rel_humidity = str(json_res_observer['points']['observed']['max_rel_humidity'])
min_rel_humidity = str(json_res_observer['points']['observed']['min_rel_humidity'])
print("\n")
print("Observer")
print("\n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment