Active
Project:
Environment Canada Weather Forecast
Version:
6.x-1.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Nov 2010 at 19:06 UTC
Updated:
15 Dec 2010 at 17:53 UTC
They are more complete, they include icon code!
But they are not in rss format.
You can find more informations here: http://dd.meteo.ec.gc.ca/
I did a small code to add a simple block in one of my site, (some weather conditions where missing in the module and I didn't wanted to add them manualy...)
$fichier = 'http://dd.meteo.ec.gc.ca/citypage_weather/xml/QC/s0000635_f.xml';
$dom = new DOMDocument();
if (!$dom->load($fichier)) {
die('Impossible de charger le fichier XML');
}
echo '<div id="meteoLienEC"><a href="http://www.meteo.gc.ca/city/pages/qc-147_metric_f.html" target="new">Environnement Canada</a>';
$currentConditions = $dom->getElementsByTagName('currentConditions');
foreach ($currentConditions as $item) {
$condition = $item->getElementsByTagName('condition');
if ($condition->length > 0) {
echo '<div id="meteoCondition" >'.$condition->item(0)->nodeValue.'</div>';
} else {
echo '(sans titre)';
}
$temperature = $item->getElementsByTagName('temperature');
if ($temperature->length >0) {
echo '<div id="meteoTemperature" >'.$temperature->item(0)->nodeValue.'°C</div>';
}
$iconCode = $item->getElementsByTagName('iconCode');
if ($iconCode->length > 0) {
echo '<div id="meteoIcon"><img id="meteoIconCode" src="ec-icons/'.$iconCode->item(0)->nodeValue.'.gif" ></div>';
}
}
Comments
Comment #1
MathGosselin commentedMy first script was loading the xml from EC each time, so I added a simple cache system.
The xml file is copied to ec/ (it needs to be writable) if it's older than one hour, all the icons are in ec/ec-icons/. When I will have more time I will make a module from it.
Comment #2
aufumy commentedHi MathGosselin, thanks for this, I did not know about the xml files.
Can you cache the files in the files directory instead of the module directory?
file_directory_path() can be used to find the files directory.
Can you please create a patch for your code contribution?
http://drupal.org/patch/create
Comment #3
MathGosselin commentedHi,
I will have more time to look into that after the Holidays. For now it's not perfect but it's working. I plan to include that xml (http://dd.meteo.ec.gc.ca/citypage_weather/docs/site_list_en.html) to be able to select the city and xml feed from a list.
Thanks for your reply!
Comment #4
aufumy commentedIt is a security risk to make directories writable outside of drupal's main files directory. Even then there is a security risk, but it is minimized, by the .htaccess that is created and managed by drupal.
I tried looking for an appropriate book page, but couldn't quite what I was looking for. Here are some general pages about permissions and the files directory.
http://drupal.org/node/244924
http://drupal.org/node/394704
http://drupal.org/node/34025
http://drupal.org/node/34028
http://drupal.org/node/202483