OpenWeather API

Had some time to putz around with a prototype of doing a weather api w/ AresMush.

It’s nothing spectacular right now, it just returns the weather in my home town. But it’s a start. I am thinking
you can have different areas setup in the config, ie, Denver, Miami, etc, with their zip code, or GPS coordinates and it will fetch the live data.

Right now it will do an api call every time you type openweather. Thinking caching it on the hour, so the game cron will trigger it.

Let me know if you guys/gals have any ideas you like to see. I’m new to Ruby, and coding for ares, so any tips/advice is welcome.

Thanks

5 Likes

That’s cool. I know there have been a couple games interested in real-world weather, so I hope you’d consider submitting it as an official Ares Extra once it’s more fleshed out.

FYI Ares does have some rest connector stuff built in (RestConnector class in the engine), so you could potentially remove the dependency on the outside rest-client gem. That would make it easier for folks to plug it into their games without having to modify their Ares gemfile.

Very excited to get this in.

I’d def want:

  • Linking an area to a zip code
  • Having that carry down to children areas if they don’t have their own zip set
  • A cron - I don’t care about every hour so much, but every few hours few sure. Dunno if there are performance implications with how often it calls.
  • Display in rooms and scenes like Ares weather does (probably requires a ‘default’ zip to catch temp rooms, too)

Thanks, I removed the rest-client dependency after peeping at the RestConnector class. Thank you for the suggestions! I’ll defiantly submitted to Extras once it’s gets hammered out.

1 Like

Ok. I’ll give this a shot. I have peek into how Ares weather currently works and make it similar. Just starting out with Ruby/Ares Coding. I’ll let ya’ll know when I have another milestone.

1 Like

I’d love if it could pull in current weather conditions. Something like: ‘It is raining and 85F.’

I’m not sure how much more difficult that’d be (if OpenWeather prints out more data or not), but it’d really help towards that room-display part.

Made some more progress today! The openweather command will pull api data for areas you define in the config file. The descriptions are a bit short, and will be expanded on

+==~~~~~====~~~~====~~~~====~~~~=====~~~~=====~~~~====~~~~====~~~~====~~~~~==+
Polar:
It is a -72.75 summer night. The weather is broken clouds.

Vegas:
It is a 91.38 summer night. The weather is clear sky.

Default:
It is a 95.23 summer night. The weather is shower rain.
+==~~~~~====~~~~====~~~~====~~~~=====~~~~=====~~~~====~~~~====~~~~====~~~~~==+

Here is the config file example

---
openweather:
   api_key: Your API Key
   units: imperial
   shortcuts: {}


  # use either zip or lat/long coordinates
   default_climate:
      zip: 78132

   climate_for_area:
      Offstage: none
      Polar:
         coords:
            lon: 40.92
            lat: -74.7
       Vegas:
            zip: 89109
2 Likes

Even succinct like that, the weather descriptions are great. I’m loving this. :slight_smile:

Very cool.

In my advanced wishlist, I’d love if we had a list of the possible weathers it can pull, and then the ability to config descriptions for that status. So ‘clear sky’ can say ‘The sky is clear, with not a cloud in sight’. Or some such.

https://openweathermap.org/weather-conditions

The api will return a code, a main weather type, and short description.

How does it sound if we put in the config file a list of return codes, and longer description? Something like below in the config.yml

weather_code_desc:
   602: A heavy snowfall makes it difficult to see far.
   615: A mix of light rain and snow falls from above. 
   800: The sky is clear, with not a cloud in sight.
2 Likes

Yup, that’d work, as long as there’s a list that lets me know what the number codes generally mean.

Incidentally, will it also return temperature in C? It might be nice to include both for our non-American friends.

Yes. You can define imperial, kelvin, or metric on the config.yml.

1 Like

Can you include both? Have it display Imperial and Metric at the same time? Or is it a ‘pick 1’ situation?

it’s a pick one thing right now, as you are asking the weather service that you want the readings in that format.

Here is a big milestone update. Example places below.

I think all is left is to tie it into room descriptions. I think this hooks in from room_desc_builder.rb in /aresmush/plugins/describe. The cron functionality is in and working, and custom descriptions are also set.

See the openweather.yml for the descriptions.

I’ll update the readme and make a pull request when I get the room desc straightend out.

README
>+==~==================================~~~~~==+

Polar:
It is -57.65°F with a humidity of 93% on this summer morning. There are 12.95 mph winds from the south southeast. Broken clouds float in the clear sky.

Vegas:
It is 61.27°F with a humidity of 33% on this summer morning. There are 3.96 mph winds from the north northeast. Broken clouds float in the clear sky.

Grand Lake:
It is 42.66°F with a humidity of 68% on this summer morning. There are 4.7 mph winds from the south southeast. The sky is clear, with not a cloud in sight.

Rocky Mountain National Park:
It is 46°F with a humidity of 65% on this summer morning. There are 5.55 mph winds from the south. The sky is clear, with not a cloud in sight.

Granby:
It is 40.5°F with a humidity of 68% on this summer morning. There are 4.7 mph winds from the south southeast. The sky is clear, with not a cloud in sight.

Sahara Desert:
It is 91.39°F with a humidity of 15% on this summer morning. There are 14.74 mph winds from the north northeast. The sky is clear, with not a cloud in sight.

Grand Rapids:
It is 67.35°F with a humidity of 93% on this summer morning. There are 3.36 mph winds from the southeast. It is misty. The air is thick with moisture, and there's just barely a light rain.

Greenland:
It is 0.49°F with a humidity of 92% on this summer morning. There are 10.94 mph winds from the southwest. Broken clouds float in the clear sky.

Default:
It is 76.14°F with a humidity of 88% on this summer morning. There are 10.54 mph winds from the south southeast. It is misty. The air is thick with moisture, and there's just barely a light rain.
+==~~~~~====~~~~====~~~~====~~~~=====~~~~=====~~~~====~~~~====~~~~====~~~~~==+
2 Likes

I live in the ‘Default’ example above, and it’s is perfectly description outside right now :slight_smile:

That’s cool.

Tying into the room descs will require people manually changing the room desc builder when they install your extra plugin. So you can just include those instructions in your README setup file. There’s no clean/reliable way to automatically patch that with an extra install unfortunately.

Alright. Here we go https://github.com/AresMUSH/ares-extras/pull/6 My first extra submit!

Enjoy all

1 Like

Awesome. I added a few review comments on the PR, and once it’s tweaked and approved it will be available as an official extra.