CVS edit link for tjodolv

About a year ago, I applied for a CVS account for a module I wrote. At the time, I was apparently not the coder I thought I was, and due to not adhering to Drupal coding standards and API, the application was turned down. After that, university studies took up most of my time, but eventually, I found time to sit down and learn Drupal. I believe I now have been able to produce a much better piece of code, one that should be ready for a new application.

The module still does the same as the original module; it implements the API of Yr.no to collect weather forecast data and display it on a Drupal site.

As for the code, the module is completely rewritten. Among other things, this has significantly shortened the amount of code.

To address the major issues from my last application:
- Dependencies are checked on install.
- Output is properly filtered by Drupal before sent to the user (and not on database storage..).
- hook_theme() is implemented, along with template files.
- I have adhered to Drupal coding standards as best I can, and have run my code through the coder.module to check if anything major is awry.
- Licensing issues regarding included image files are no longer a problem, as none are included. Yr.no allows hotlinking to their image resources, as long as a link back to them is displayed, which I do in this module.

Although Yr.no's API is primarily targeted at Norwegian-speaking users, the do deliver their data in English as well, making the target audience for this module the same as any other weather-API.

A demo is available at http://krkh.info/yr_verdata/1 (site is in Norwegian, but the functionality of the module is the same).

Previous applications below:
--------------------------------------------
I recently applied for a CVS account for a module I have written (original cvs application at the bottom of this one). The application was turned down with the message:
"One size can fit all if you are prepared to do the work of integration. But you'd first need to discuss that with the current module maintainer. If they are not interested in expanding their module with external help then another module is possible. But please follow that route first."

While I could contact the maintainer of the "weather" module, I do not believe that integrating my module with that one is a logical way to do it. I did some more looking around, and I found that there are already two other weather forecast modules on drupal.org. In total three, each utilizing a different API (weather uses METAR, yahoo_weather uses Yahoo's weather API and ecweather uses Environment Canada's forecast data). My module implements yet another API, and I see no reason to deny another API to be added in its own module, as is already the case with these others.

Original application below:
--------------------------------------------
I am maintaining a couple of Drupal sites, and in doing so, I have written a small module for one of them. I realized it might be worth sharing, so here is my application.

The module in question is named Verdata, and is a weather forecast module. I realize there is already a similar module here on drupal.org, but this one differs in that it uses another weather service. The service is http://yr.no, which is a Norwegian service, also available in English. There are more than 7 million worldwide locations available from yr.no, even including research stations in Antarctica! A demo of my module is available at http://drupaldev.freka.net/node/4, including the code.

The reason I wanted to create this module was simply because I believe there is room for another weather module. One size does not fit all, and METAR's API differs from that of yr.no. Some parts of the yr.no API are more suited for use in Norway (e.g. licensing on radar images restricts verdata.module from using radar images outside mainland Norway), but I believe there is adequate features in it for people outside Norway to find it useful. Leveraging yr.no's API, it provides short- and long-term forecasts up to one week ahead, for all locations. METAR's API is also currently limited to major airports as far as I know, while yr.no delivers forecast for – as previously mentioned – more than 7 million locations.

Comments

tjodolv’s picture

Component: Miscellaneous » Code
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new24.35 KB
avpaderno’s picture

Component: Code » Miscellaneous
Issue tags: +Module review

Please change only the status, when you upload a new version of the code; other meta data are not thought to be changed by the applicant (and they are not usually changed).

avpaderno’s picture

Status: Needs review » Needs work

Giving a quick peek to the code I noticed that:

  1.   while ($row = db_fetch_array($result)) {
        $tmp = explode('/', $row['url']);
        $row['title'] = $tmp[3];
        $row['title'] .= (isset($tmp[4])) ? ' - '. $tmp[4] : '';
        $row['title'] .= ', '. $tmp[2] .', '. $tmp[1];
        $rows[] = array($row['yid'], l($row['title'], 'yr_verdata/'. $row['yid']), l('X', 'admin/content/yr_verdata/delete/'. $row['yid']));
      }
    

    The row title is a concatenation of string, and it is not translatable; as it is used in a link, it would be better to make it translatable. To notice that using t($row['title']) would not resolve the problem as the first argument of the function needs to be a literal string (not even a concatenation of literal string), otherwise the script used to extract the strings to translate would not extract that string.

  2. function yr_verdata_delete_location($form, $yid) {
      (int) $yid;
    

    That code doesn't do anything, as the returned value is not saved in a variable; maybe the code should be $yid = (int) $yid, even if it's not clear why the variable content should be casted to an integer when PHP does that automatically (if you write $a = 1 + "5isaninteger", PHP will assign 6 to $a).

tjodolv’s picture

Status: Needs work » Needs review
StatusFileSize
new431 bytes

Thank you for the quick review. As for the issues you mention:

  1. The $row['title'] variable is built from the actual name of the location, as input by the user. As such, setting up a translation method for this is not doable with Drupal's t(), as there is no literal string to pass as an argument.
  2. Fixed. Attached a patch.
tjodolv’s picture

StatusFileSize
new1.06 KB

Whoops, I also found a weakness in the logic for resolving if a certain day in the detailed forecast is to be closed or not.
yr_verdata.module, line 246:

$close = (($tab['period'] == 3) || (($tab['period'] == 2) && ($last_period != 1))) ? '</div>' : '';

Should be:

$close = (($tab['period'] == 3) || (($tab['period'] == 2) && ($last_period != 1) && ($i != 0))) ? '</div>' : '';

New patch attached. Disregard previous patch.

avpaderno’s picture

Status: Needs review » Needs work

Please upload the full archive, not a patch; who reviews the code (there are more than one reviewer) should otherwise get the previous last archive, apply the patch, and review the code.

tjodolv’s picture

Status: Needs work » Needs review
StatusFileSize
new18.63 KB

Ah, I apologize. Here is a new, complete build.

avpaderno’s picture

Status: Needs review » Fixed
  1.   $location['info'] = $data->location->type .', '. $data->location->location['altitude'] . t(' m.a.s. <br />Last updated ');
    

    Using placeholders (using something like "@type, @altitude m.a.s. <br />Last updated" could be better; the string you are appending could be pre-prended, in some languages.

  2.       $location['text_forecast'][] = array('title' => ucfirst($item->title), 'body' => $item->body);
    

    Drupal coding standards suggest to use Drupal Unicode functions when available (see drupal_strtoupper(), drupal_strtolower(), etc...).

  3.   if (($lat >= 57)&&($lat < 62)&&($long >= 5)&&($long < 7)) {
    

    Put a space before and after &&.

  4. t('The first part of the url at <a href="http://yr.no">yr.no</a> (after <em>http://yr.no/place/</em>). For example: http://yr.no/place/<strong>Norway</strong>/Vest-Agder/Kristiansand/Hamresanden.')
    

    The URLs should be put in the string through placeholders, if there isn't a different link for each supported languages; to make an example, if I would report a link to the function ucfirst in PHP.net, I would put it directly into the string (as the English version would use a link to http://www.php.net/manual/en/function.ucfirst.php, while the German version would use http://www.php.net/manual/de/function.ucfirst.php)

  5.   if (db_affected_rows() == 1) {
        $form['delete_location']['name'] = array(
          '#type' => 'item',
          '#value' => t('Warning: You are about to delete the location <strong>@location</strong> from the database. This action cannot be undone.', array('@location' => $row->url)),
        );
    

    Normally, the used string would be 'Warning: You are about to delete the location %location from the database. This action cannot be undone.'

  6. $(document).ready( function() {
      $(document).ready(function(){
        $("#yr-forecast-page > ul").tabs({ fx: { opacity: 'toggle' } });
      });
    });
    

    It should be

    $(document).ready( function() {
        $("#yr-forecast-page > ul").tabs({ fx: { opacity: 'toggle' } });
    });
    
tjodolv’s picture

Thank you for your time! I have corrected the issues you mentioned in your last post.
Again, thank you for your time and effort.

Status: Fixed » Closed (fixed)
Issue tags: -Module review

Automatically closed -- issue fixed for 2 weeks with no activity.

avpaderno’s picture

Component: Miscellaneous » new project application
Assigned: Unassigned » avpaderno
Issue summary: View changes
Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.