Skip to content

Instantly share code, notes, and snippets.

@nwhobart
Created September 24, 2018 20:23
Show Gist options
  • Save nwhobart/ecf1f1e1f3846483b1b62f0111c0938c to your computer and use it in GitHub Desktop.
Save nwhobart/ecf1f1e1f3846483b1b62f0111c0938c to your computer and use it in GitHub Desktop.
Temperature check
#!/usr/bin/env python3
import geocoder
import argparse
import json
from darksky import forecast
tomkey = ''
darkkey = ''
locations = {
'work': '',
'home': '',
'bliss': '',
'cabin': ''
}
parser = argparse.ArgumentParser(description='Weather, son.')
parser.add_argument('locations', nargs='?', const=1, default="home", help='name of city, state')
args = parser.parse_args()
def wx(location):
latlng = geocoder.tomtom(location, key=tomkey).latlng
info = forecast(darkkey, latlng[0], latlng[1])
wx = json.dumps({
"current_temp": info.temperature,
"current_dew_point": info.dewPoint,
"todays_high": info['daily']['data'][0]['temperatureHigh'],
"summary": info['hourly']['summary']})
return wx
print(wx(locations.get(args.locations, args.locations)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment