Skip to content

Instantly share code, notes, and snippets.

@tym-xqo
Last active August 29, 2015 14:21
Show Gist options
  • Save tym-xqo/563b7f0272118ab70e68 to your computer and use it in GitHub Desktop.
Save tym-xqo/563b7f0272118ab70e68 to your computer and use it in GitHub Desktop.
Quick location and weather from Forecast.io - (I removed the location.py because of Whereami. This whole gist will be deleted eventually)
#!/usr/bin/env python
# coding: utf-8
import os
import forecastio
import json
from time import strftime
# Get an API key at https://developer.forecast.io
# and add to your local environment
api_key = os.getenv('FORECASTIO_KEY')
with open('/home/ubuntu/Dropbox/loc.json', 'r') as loc_file:
loc = json.load(loc_file)
tim = strftime('%H:%M:%S')
lat = loc['latitude']
lng = loc['longitude']
forecast = forecastio.load_forecast(api_key, lat, lng)
dp = forecast.currently()
# writes temp and chance of precip, along with time and geo coordinates, to a file in my Dropbox
# then I have $(tail -n 1 ~/Dropbox/weav) in my PS1
with open ('/path/to/Dropbox/weav', 'a') as outfile:
outfile.write('%sº@%s | %s%% | %s,%s\n' % (dp.temperature, tim, dp.precipProbability, lat, lng))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment