require 'date' require 'httparty' require 'json' COMPASS_LOCATION_READ_TOKEN="" COMPASS_WEATHER_WRITE_TOKEN="" WUNDERGROUND_API_KEY="" data = JSON.parse(HTTParty.get('https://compass.p3k.io/api/last?token='+COMPASS_LOCATION_READ_TOKEN).body) location = data['data'] timestamp = DateTime.parse(location['properties']['timestamp']).to_time.to_i latitude = location['geometry']['coordinates'][] longitude = location['geometry']['coordinates'][] accuracy = location['properties']['accuracy'] if latitude url = "http://api.wunderground.com/api/#{WUNDERGROUND_API_KEY}/conditions/q/#{latitude},#{longitude}.json" weather = JSON.parse(HTTParty.get(url).body) puts "#{weather['current_observation']['temp_f']}F #{weather['current_observation']['weather']}" weather = { :type => 'Feature', :geometry => { :type => 'Point', :coordinates => [longitude, latitude] }, :properties => { :timestamp => Time.now.strftime('%Y-%m-%dT%H:%M:%SZ'), :location_date_utc => Time.at(timestamp), :location_timezone => weather['current_observation']['local_tz_long'], :location_accuracy => accuracy, :temp_f => weather['current_observation']['temp_f'], :humidity => weather['current_observation']['relative_humidity'].gsub('%',''), :pressure_mb => weather['current_observation']['pressure_mb'], :feelslike_f => weather['current_observation']['feelslike_f'], :description => weather['current_observation']['weather'], :icon => weather['current_observation']['icon'], :wind_mph => weather['current_observation']['wind_mph'], :wind_gust_mph => weather['current_observation']['wind_gust_mph'], :precip_1hr_metric => weather['current_observation']['precip_1hr_metric'].gsub(' ',''), } } result = HTTParty.post("https://compass.p3k.io/api/input", { body: { locations: [weather], token: COMPASS_WEATHER_WRITE_TOKEN }.to_json, headers: { 'Content-type' => 'application/json' } }) puts result.body end
WeChat ID
aaronpk_tv