Skip to content

Instantly share code, notes, and snippets.

@kkenny
Created January 31, 2013 15:15
Show Gist options
  • Save kkenny/4683552 to your computer and use it in GitHub Desktop.
Save kkenny/4683552 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import argparse
import socket
import time
CARBON_SERVER = ''
CARBON_PORT = 2003
parser = argparse.ArgumentParser()
parser.add_argument('metric_path')
parser.add_argument('value')
args = parser.parse_args()
if __name__ == '__main__':
timestamp = int(time.time())
message = '%s %s %d\n' % (args.metric_path, args.value, timestamp)
print 'sending message:\n%s' % message
sock = socket.socket()
sock.connect((CARBON_SERVER, CARBON_PORT))
sock.sendall(message)
sock.close()
require 'open-uri'
require 'json'
time = Time.new
open('http://api.wunderground.com/api/get_your_own_key/geolookup/conditions/q/IN/Noblesville.json') do |f|
json_string = f.read
parsed_json = JSON.parse(json_string)
state = parsed_json['location']['state']
city = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
temp_c = parsed_json['current_observation']['temp_c']
wind_degrees = parsed_json['current_observation']['wind_degrees']
wind_mph = parsed_json['current_observation']['wind_mph']
wind_gust_mph = parsed_json['current_observation']['wind_gust_mph']
pressure_in = parsed_json['current_observation']['pressure_in']
dewpoint_f = parsed_json['current_observation']['dewpoint_f']
windchill_f = parsed_json['current_observation']['windchill_f']
windchill_c = parsed_json['current_observation']['windchill_c']
feelslike_f = parsed_json['current_observation']['feelslike_f']
feelslike_c = parsed_json['current_observation']['feelslike_c']
vis_mi = parsed_json['current_observation']['visibility_mi']
uv = parsed_json['current_observation']['UV']
precip_1hr_in = parsed_json['current_observation']['precip_1hr_in']
precip_today_in = parsed_json['current_observation']['precip_today_in']
print "weather.#{state}.#{city}.temperature.f #{temp_f}\n"
print "weather.#{state}.#{city}.temperature.c #{temp_c}\n"
print "weather.#{state}.#{city}.feelslike.f #{feelslike_f}\n"
print "weather.#{state}.#{city}.feelslike.c #{feelslike_c}\n"
print "weather.#{state}.#{city}.windchill.f #{windchill_f}\n"
print "weather.#{state}.#{city}.windchill.c #{windchill_c}\n"
print "weather.#{state}.#{city}.wind.degrees #{wind_degrees}\n"
print "weather.#{state}.#{city}.wind.mph #{wind_mph}\n"
print "weather.#{state}.#{city}.wind.gust.mph #{wind_gust_mph}\n"
print "weather.#{state}.#{city}.dewpoint.f #{dewpoint_f}\n"
print "weather.#{state}.#{city}.pressure.in #{pressure_in}\n"
print "weather.#{state}.#{city}.visibility.miles #{vis_mi}\n"
print "weather.#{state}.#{city}.uv #{uv}\n"
print "weather.#{state}.#{city}.precipitation.1hr.in #{precip_1hr_in}\n"
print "weather.#{state}.#{city}.precipitation.today #{precip_today_in}\n"
print "weather.#{state}.#{city}.precipitation.#{time.year}.#{time.month}.#{time.day} #{precip_today_in}\n"
end
ruby /usr/local/scripts/get_weather.rb | while read a b; do /usr/local/scripts/gclient.py $a $b; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment