Jump to content

Yahoo! Weather Module


Recommended Posts

Hi guys,

It's been a while that I've posted here on the forum, the reason was - I got a new job few months ago so I've been rather busy and haven't got time to post some new things.

I've made a Yahoo! Weather module that connects to Yahoo weather API and pulls current forecast and forecast for next 4 days. The module is completely ready for translation, I've also made days and weather conditions translatable because Yahoo API doesn't offer localization (English only). The widget has normal mode and compact mode and you can easily customize it's appearance through included CSS.

Edit 12.04.2015.

This module is not longer supported, check out the new version at this link. I'll fix some errors that are currently in this module for those of you who like the old version better then the newer one.





How to install

Copy module directory to /site/modules/ directory.

Click check for new modules in ProcessWire Admin Modules screen. Click *install* for the module labeled: "MarkupWeather".

How to use

Copy this line to template of your choice where you want the weather widget to be displayed:

<?php echo $modules->get('MarkupWeather')->render(); ?>

This module has the following options:

Yahoo! Weather Woeid
Woeid is a number located right beside the city name, e.g. http://weather.yahoo.com/croatia/grad-zagreb/zagreb-851128/

Set Locale
sets PHP locale, needed for date display localization

Date Format
date formatted with PHP strftime function

Show 5 day forecast below current weather forecast?
turn this off if you want to display compact weather widget, shows only current weather

Display temperature in Fahrenheit instead of Celsius?
show weather conditions in Celsius or Fahrenheit scale

Hope you'll like it.

  • Like 14
Link to comment
Share on other sites

I tried this module and it works great !

A little thing about the CSS:

/* Most Frameworks render with box-sizing: border-box;, but your CSS is made for content-box */

#weather {
    box-sizing: content-box;

#weather * {
    box-sizing: content-box;

/* prevent scrolling & box collapse */
#weather .current {
    overflow: visible;
Link to comment
Share on other sites

Awesome Nikola! I really like this module. Just a few suggestions:

  • The module should not extend Process since it's not an admin process. Instead it should extend WireData. 
  • The module should not be autoload since it is loaded from an API call instead. 
  • Ideally the module would be called MarkupWeather or MarkupYahooWeather, since the "Markup" prefix is recommended for all markup-generation modules. 
  • Please add it to the modules directory as soon as you get the chance. It's a lot simpler to do now, as the modules directory pulls most stuff right from your GitHub page.
  • Like 2
Link to comment
Share on other sites

  • 4 months later...

I had a need to output two sets of weather conditions. You can achieve this by simply passing the woeid before rendering the output like this:

$weather = $modules->get('MarkupWeather');
// Husum, Germany
$weather->woeid = 24907;
echo $weather->render();
// Kidderminster, England
$weather->woeid = 663053;
echo $weather->render();

I've got a few ideas for improving this module and might have a go at them when I get a sec:

  1. Allow for multiple locations in config
  2. Have the module install the output as a template in the site/templates folder (so future upgrades don't break any template changes)

I think that's it really - other than that it's awesome :)

Link to comment
Share on other sites

  • 1 year later...

Hi guys, thank you nikola for this module just one thing i found to solve is the check if $result was true and the file_get_contents(); work....

for me some short times the service API was not available so the whole render() give me an error and break the whole page....not so good if you use this one as widget or on every page and so on...

Did a pull request on github and here i post the german lang file.... ;)

Thank you again for this great widget!

best regards mr-fan


  • Like 1
Link to comment
Share on other sites

I've found that for some issues the replacement of the conditions text did not work...on some strings.

like i wrote in the german translations threat...there are some problem to get the strings.

$out .= "<div class='conditions'>" . __("Current Conditions:", __FILE__) . " <span>" . str_replace(array_keys($conditions), $conditions, $current['text']) . "</span></div>";

so it would be saver if we don't replace the text and use the conditions code for this one...if i found some time on "ostern" may i could run a test and a PR for this.

So we get the condition Code - and check if this code is not there so no condition output....so we get no weird outputs.

regards mr-fan

Link to comment
Share on other sites

So problem solved the Module gets a PR on github changed the array for the condition strings...so we can use the API code as keys and load the condition better.

And have build in a if for the condition itself - so if the API code change or a new one is added we get no error on the frontend just the condition has no output anymore...so it's a little bit saver for the API code <=> condition text stuff.

Please have a look and make a new merge if you accepted/tested the changes?

best regards mr-fan

crosslink to the new german lang file (backend translated, too)

Link to comment
Share on other sites

Thanks, mr-fan, I had a look on your pull request and it looks fine. I'll merge it these days ;)

I'm planning to update a module a little bit these days, I have to change the icons to newer ones (maybe weather icon font...)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...