Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import platform
import requests
class Weather:
def __init__(self, agentConfig, checksLogger, rawConfig):
self.agentConfig = agentConfig
self.checksLogger = checksLogger
self.rawConfig = rawConfig
self.version = platform.python_version_tuple()
self.token = 'api.forecast.io.key'
self.long = '51.4800'
self.lat = '0.0000'
self.fields = ['temperature', 'nearestStormDistance', 'windSpeed', 'humidity', 'pressure']
def run(self):
data = {}
try:
r = requests.get('https://api.forecast.io/forecast/%s/%s,%s?units=si' % (self.token, self.long, self.lat))
for field in self.fields:
data[field] = 0
try:
data[field] = r.json()['currently'][field]
except:
pass
except:
pass
return data
@bassdread

This comment has been minimized.

Copy link
Owner Author

commented Jun 15, 2014

units=si turns on metric measurements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.