91°F

Aaron Parecki

  • Articles
  • Notes
  • Photos
  • weather.rb

    July 3, 2018
    1. require 'date'
    2. require 'httparty'
    3. require 'json'
    4.  
    5. COMPASS_LOCATION_READ_TOKEN=""
    6. COMPASS_WEATHER_WRITE_TOKEN=""
    7. WUNDERGROUND_API_KEY=""
    8.  
    9. data = JSON.parse(HTTParty.get('https://compass.p3k.io/api/last?token='+COMPASS_LOCATION_READ_TOKEN).body)
    10. location = data['data']
    11.  
    12. timestamp = DateTime.parse(location['properties']['timestamp']).to_time.to_i
    13. latitude = location['geometry']['coordinates'][]
    14. longitude = location['geometry']['coordinates'][]
    15. accuracy = location['properties']['accuracy']
    16.  
    17. if latitude
    18. url = "http://api.wunderground.com/api/#{WUNDERGROUND_API_KEY}/conditions/q/#{latitude},#{longitude}.json"
    19. weather = JSON.parse(HTTParty.get(url).body)
    20.  
    21. puts "#{weather['current_observation']['temp_f']}F #{weather['current_observation']['weather']}"
    22.  
    23. weather = {
    24. :type => 'Feature',
    25. :geometry => {
    26. :type => 'Point',
    27. :coordinates => [longitude, latitude]
    28. },
    29. :properties => {
    30. :timestamp => Time.now.strftime('%Y-%m-%dT%H:%M:%SZ'),
    31. :location_date_utc => Time.at(timestamp),
    32. :location_timezone => weather['current_observation']['local_tz_long'],
    33. :location_accuracy => accuracy,
    34. :temp_f => weather['current_observation']['temp_f'],
    35. :humidity => weather['current_observation']['relative_humidity'].gsub('%',''),
    36. :pressure_mb => weather['current_observation']['pressure_mb'],
    37. :feelslike_f => weather['current_observation']['feelslike_f'],
    38. :description => weather['current_observation']['weather'],
    39. :icon => weather['current_observation']['icon'],
    40. :wind_mph => weather['current_observation']['wind_mph'],
    41. :wind_gust_mph => weather['current_observation']['wind_gust_mph'],
    42. :precip_1hr_metric => weather['current_observation']['precip_1hr_metric'].gsub(' ',''),
    43. }
    44. }
    45.  
    46. result = HTTParty.post("https://compass.p3k.io/api/input", {
    47. body: {
    48. locations: [weather],
    49. token: COMPASS_WEATHER_WRITE_TOKEN
    50. }.to_json,
    51. headers: {
    52. 'Content-type' => 'application/json'
    53. }
    54. })
    55.  
    56. puts result.body
    57. end
    Portland, Oregon • 61°F
    Tue, Jul 3, 2018 11:55am -07:00
    1 reply
    • Aaron Parecki aaronparecki.com
      Sure thing! Here's the script I use, you'll need to fill in the three API keys at the top of the file, and of course replace compass.p3k.io with your own domain. https://aaronparecki.com/2018/07/03/7/
      Tue, Jul 3, 2018 11:56am -07:00
Posted in /code using quill.p3k.io

Hi, I'm Aaron Parecki, Director of Identity Standards at Okta, and co-founder of IndieWebCamp. I maintain oauth.net, write and consult about OAuth, and participate in the OAuth Working Group at the IETF. I also help people learn about video production and livestreaming. (detailed bio)

I've been tracking my location since 2008 and I wrote 100 songs in 100 days. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel. Read more.

  • Director of Identity Standards at Okta
  • IndieWebCamp Founder
  • OAuth WG Editor
  • OpenID Board Member

  • 🎥 YouTube Tutorials and Reviews
  • 🏠 We're building a triplex!
  • ⭐️ Life Stack
  • ⚙️ Home Automation
  • All
  • Articles
  • Bookmarks
  • Notes
  • Photos
  • Replies
  • Reviews
  • Trips
  • Videos
  • Contact
© 1999-2025 by Aaron Parecki. Powered by p3k. This site supports Webmention.
Except where otherwise noted, text content on this site is licensed under a Creative Commons Attribution 3.0 License.
IndieWebCamp Microformats Webmention W3C HTML5 Creative Commons
WeChat ID
aaronpk_tv