Last active
August 29, 2015 14:02
-
-
Save bassdread/9b9925c1cc793dcba1d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
units=si turns on metric measurements