Skip to content

Instantly share code, notes, and snippets.

@whoizit
Created March 16, 2020 08:51
Show Gist options
  • Save whoizit/f861ada34339f8e8dc79d606fc63ae5b to your computer and use it in GitHub Desktop.
Save whoizit/f861ada34339f8e8dc79d606fc63ae5b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# pip install -U python-dotenv requests
# https://developer.accuweather.com/accuweather-current-conditions-api/apis/get/currentconditions/v1/%7BlocationKey%7D
import os
import operator
import functools
import requests
import dotenv
dotenv.load_dotenv()
url = 'http://dataservice.accuweather.com/currentconditions/v1/{CITY_ID}?apikey={API_KEY}&language={LANG}&details=true'.format(
CITY_ID=os.environ['ACCU_CITY_ID'],
API_KEY=os.environ['ACCU_API_KEY'],
LANG=os.environ['ACCU_LANG'],
)
r = requests.get(url)
json = r.json()[0]
def f(s):
return functools.reduce(operator.getitem, s.split('/'), json)
print(
"{}°({}°), {}, {}%".format(
f('Temperature/Metric/Value'),
f('RealFeelTemperature/Metric/Value'),
f('WeatherText'),
f('RelativeHumidity'),
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment