Besoin d'aide pour ajouter de la météo locale à l'alimentation de mon site

  • Realty
  • Newbie
  • Newbie
  • Avatar de l’utilisateur
  • Inscription: Nov 15, 2008
  • Messages: 8
  • Loc: Mozambique & Bahamas
  • Status: Offline

Message Novembre 15th, 2008, 7:47 am

Bonjour webmasters,

J'ai un site et je tiens à ajouter la météo locale, mais je n'ai aucune idée comment le faire.

Je pouvais utiliser la Codding de weather.com et le placer dans une de mes pages, mais il montre l'information de trop.

Donc, après beaucoup de recherche que j'ai constaté que je pouvais aussi utiliser les flux météo de Yahoo: Yahoo! Météo - Yahoo! Developer Network

J'ai pu suivre leurs instructions et j'ai maintenant le code ci-dessous:


Code: [ Select ]
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://weather.yahooapis.com/ns/rss/1.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Nassau, NP</title>
<link>http://us.rd.yahoo.com/dailynews/rss...er/Nassau__BF/
*http://weather.yahoo.com/forecast/94089_f.html</link>
<description>Yahoo! Weather for Nassau, NP</description>
<language>en-us</language>
<lastBuildDate>Tue, 29 Nov 2005 3:56 pm PST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Nassau" region="NP" country="BS"></yweather:location>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"></yweather:units>
<yweather:wind chill="57" direction="350" speed="7"></yweather:wind>
<yweather:atmosphere humidity="93" visibility="1609" pressure="30.12" rising="0"></yweather:atmosphere>
<yweather:astronomy sunrise="7:02 am" sunset="4:51 pm"></yweather:astronomy>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com/</link>
<url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Nassau, NP at 3:56 pm PST</title>
<geo:lat>37.39</geo:lat>
<geo:long>-122.03</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/
<span style="font-size: 0px"> </span>Nassau__BF/*
<span style="font-size: 0px"> </span>http://weather.yahoo.com/<span style="font-size: 0px"> </span>forecast/BFXX0005_f.html
</link>
<pubDate>Tue, 29 Nov 2005 3:56 pm PST</pubDate>
<yweather:condition text="Mostly Cloudy" code="26" temp="57" date="Tue, 29 Nov 2005 3:56
pm PST"></yweather:condition>
<description><![CDATA[
<img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/26.gif" /><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 57 F<p />
<b>Forecast:</b><BR />
Tue - Mostly Cloudy. High: 62 Low: 45<br />
Wed - Mostly Cloudy. High: 60 Low: 52<br />
Thu - Rain. High: 61 Low: 46<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Nassau__BF/*http://weather.yahoo.com/forecast/BFXX0005_f.html">Full Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>]]>
</description>
<yweather:forecast day="Tue" date="29 Nov 2005" low="45" high="62" text="Mostly Cloudy"
code="27"></yweather:forecast>
<yweather:forecast day="Wed" date="30 Nov 2005" low="52" high="60" text="Mostly Cloudy"
code="28"></yweather:forecast>
<guid isPermaLink="false">94089_2005_11_29_15_56_PST</guid>
</item>
</channel>
</rss>
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  2. <rss version="2.0" xmlns:yweather="http://weather.yahooapis.com/ns/rss/1.0"
  3. xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  4. <channel>
  5. <title>Yahoo! Weather - Nassau, NP</title>
  6. <link>http://us.rd.yahoo.com/dailynews/rss...er/Nassau__BF/
  7. *http://weather.yahoo.com/forecast/94089_f.html</link>
  8. <description>Yahoo! Weather for Nassau, NP</description>
  9. <language>en-us</language>
  10. <lastBuildDate>Tue, 29 Nov 2005 3:56 pm PST</lastBuildDate>
  11. <ttl>60</ttl>
  12. <yweather:location city="Nassau" region="NP" country="BS"></yweather:location>
  13. <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"></yweather:units>
  14. <yweather:wind chill="57" direction="350" speed="7"></yweather:wind>
  15. <yweather:atmosphere humidity="93" visibility="1609" pressure="30.12" rising="0"></yweather:atmosphere>
  16. <yweather:astronomy sunrise="7:02 am" sunset="4:51 pm"></yweather:astronomy>
  17. <image>
  18. <title>Yahoo! Weather</title>
  19. <width>142</width>
  20. <height>18</height>
  21. <link>http://weather.yahoo.com/</link>
  22. <url>http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
  23. </image>
  24. <item>
  25. <title>Conditions for Nassau, NP at 3:56 pm PST</title>
  26. <geo:lat>37.39</geo:lat>
  27. <geo:long>-122.03</geo:long>
  28. <link>http://us.rd.yahoo.com/dailynews/rss/weather/
  29. <span style="font-size: 0px"> </span>Nassau__BF/*
  30. <span style="font-size: 0px"> </span>http://weather.yahoo.com/<span style="font-size: 0px"> </span>forecast/BFXX0005_f.html
  31. </link>
  32. <pubDate>Tue, 29 Nov 2005 3:56 pm PST</pubDate>
  33. <yweather:condition text="Mostly Cloudy" code="26" temp="57" date="Tue, 29 Nov 2005 3:56
  34. pm PST"></yweather:condition>
  35. <description><![CDATA[
  36. <img src="http://us.i1.yimg.com/us.yimg.com/i/us/we/52/26.gif" /><br />
  37. <b>Current Conditions:</b><br />
  38. Mostly Cloudy, 57 F<p />
  39. <b>Forecast:</b><BR />
  40. Tue - Mostly Cloudy. High: 62 Low: 45<br />
  41. Wed - Mostly Cloudy. High: 60 Low: 52<br />
  42. Thu - Rain. High: 61 Low: 46<br />
  43. <br />
  44. <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Nassau__BF/*http://weather.yahoo.com/forecast/BFXX0005_f.html">Full Forecast at Yahoo! Weather</a><BR/>
  45. (provided by The Weather Channel)<br/>]]>
  46. </description>
  47. <yweather:forecast day="Tue" date="29 Nov 2005" low="45" high="62" text="Mostly Cloudy"
  48. code="27"></yweather:forecast>
  49. <yweather:forecast day="Wed" date="30 Nov 2005" low="52" high="60" text="Mostly Cloudy"
  50. code="28"></yweather:forecast>
  51. <guid isPermaLink="false">94089_2005_11_29_15_56_PST</guid>
  52. </item>
  53. </channel>
  54. </rss>

Quelqu'un peut-il me dire comment utiliser ce code pour que je puisse afficher les conditions météorologiques sur mon site en format flux RSS?

Je suis nouvelle dans la conception des sites, s'il vous plaît aider.

Observe,
Realty
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Novembre 15th, 2008, 7:47 am

  • digitalMedia
  • a.k.a. dM
  • Genius
  • Avatar de l’utilisateur
  • Inscription: Déc 29, 2003
  • Messages: 5169
  • Loc: SC-USA
  • Status: Offline

Message Novembre 15th, 2008, 8:58 am

Vous avez besoin d'un RSS Parser. Si vous utilisez PHP, vous pouvez vérifier Magpie...http://magpierss.sourceforge.net/
- dM
  • righteous_trespasser
  • Scuffle
  • Genius
  • Avatar de l’utilisateur
  • Inscription: Mar 12, 2007
  • Messages: 6228
  • Loc: South-Africa
  • Status: Offline

Message Novembre 15th, 2008, 2:13 pm

J'ai écrit un tutorial à ce sujet: php-tutorials/tutorial-read-weather-from-yahoo-weather-with-php-t88164.html
Let's leave all our *plum* where it is and go live in the jungle ...
  • Realty
  • Newbie
  • Newbie
  • Avatar de l’utilisateur
  • Inscription: Nov 15, 2008
  • Messages: 8
  • Loc: Mozambique & Bahamas
  • Status: Offline

Message Novembre 15th, 2008, 8:42 pm

righteous_trespasser a écrit:
J'ai écrit un tutoriel à ce sujet: php-tutorials/tutorial-read-weather-from-yahoo-weather-with-php-t88164.html


Bonjour là,

Merci pour le tutoriel.
Comme je le disais dans mon premier post, je suis nouveau avec les codes et je voudrais en savoir plus.

Dans votre tutorial, vous devez d'abord expliqué en xml, puis en php, et que vous avez également démontré l'alimentation de votre emplacement.

J'ai déjà mon flux: http://weather.yahooapis.com/forecastrss?p=BFXX0005&u=f et je voudrais préparer ma page (index.html) et être en mesure de lire ce flux.

Mes questions sont les suivantes (je sais qu'il mai sonore stupide, mais j'ai besoin de mieux comprendre)
1) Dois-je les mettre dans des codes, dire: xyz.xml et xyz.php et ensuite les télécharger sur mon serveur ma page d'index où est situé?

2) Quel code / ligne dois-je utiliser pour mettre sur ma page (index.html)?
Ci-dessous, est l'un des exemples dont je parle.
http://www.mariocareyrealty.com/index.php

Merci d'avance.
Realty
  • righteous_trespasser
  • Scuffle
  • Genius
  • Avatar de l’utilisateur
  • Inscription: Mar 12, 2007
  • Messages: 6228
  • Loc: South-Africa
  • Status: Offline

Message Novembre 16th, 2008, 1:35 am

Realty a écrit:
1) Dois-je sauver ces codes en séparant par exemple: xyz.xml et xyz.php et ensuite les transférer sur mon serveur sur lequel ma page d'index se trouve?

Le fichier XML que vous obtiendriez de la page de Yahoo, cet page est le XML...
Realty a écrit:
2) Quel code / ligne dois-je utiliser pour placer sur ma page (index.html)?

Dans mon tutoriel, vous pouvez placer cette PHP ci-dessous où vous voulez le temps de montrer...tu peux retirer les guillemets...également la page d'index sera nommé index.php et pas index.html...
Code: [ Select ]
<?php
//I am using the DOM(Document Object Model) library to read the entire XML document into memory first.
$doc = new DOMDocument();
$doc->load('http://weather.yahooapis.com/forecastrss?p=SFXX0044&u=c');
//now I get all elements inside this document with the following name "channel", this is the 'root'
$channel = $doc->getElementsByTagName("channel");
//now I go through each item withing $channel
foreach($channel as $chnl)
{
//I then find the 'item' element inside that loop
$item = $chnl->getElementsByTagName("item");
foreach($item as $itemgotten)
{
//now I search within '$item' for the element "description"
$describe = $itemgotten->getElementsByTagName("description");
//once I find it I create a variable named "$description" and assign the value of the Element to it
$description = $describe->item(0)->nodeValue;
//and display it on-screen
echo $description;
}
}
?>
  1. <?php
  2. //I am using the DOM(Document Object Model) library to read the entire XML document into memory first.
  3. $doc = new DOMDocument();
  4. $doc->load('http://weather.yahooapis.com/forecastrss?p=SFXX0044&u=c');
  5. //now I get all elements inside this document with the following name "channel", this is the 'root'
  6. $channel = $doc->getElementsByTagName("channel");
  7. //now I go through each item withing $channel
  8. foreach($channel as $chnl)
  9. {
  10. //I then find the 'item' element inside that loop
  11. $item = $chnl->getElementsByTagName("item");
  12. foreach($item as $itemgotten)
  13. {
  14. //now I search within '$item' for the element "description"
  15. $describe = $itemgotten->getElementsByTagName("description");
  16. //once I find it I create a variable named "$description" and assign the value of the Element to it
  17. $description = $describe->item(0)->nodeValue;
  18. //and display it on-screen
  19. echo $description;
  20. }
  21. }
  22. ?>
Let's leave all our *plum* where it is and go live in the jungle ...
  • digitalMedia
  • a.k.a. dM
  • Genius
  • Avatar de l’utilisateur
  • Inscription: Déc 29, 2003
  • Messages: 5169
  • Loc: SC-USA
  • Status: Offline

Message Novembre 17th, 2008, 4:06 am

Doh! J'ai oublié ton écrit le tut r_t. My bad. :)
- dM
  • Realty
  • Newbie
  • Newbie
  • Avatar de l’utilisateur
  • Inscription: Nov 15, 2008
  • Messages: 8
  • Loc: Mozambique & Bahamas
  • Status: Offline

Message Novembre 17th, 2008, 8:33 am

Bonjour righteous_trespasser,

Merci.
Maintenant je vois pourquoi ne fonctionnait pas.
Le temps les codes sont en php et mes sites sont en html.

Je vais essayer de trouver une autre façon.
Merci pour votre aide.

Realty
  • Realty
  • Newbie
  • Newbie
  • Avatar de l’utilisateur
  • Inscription: Nov 15, 2008
  • Messages: 8
  • Loc: Mozambique & Bahamas
  • Status: Offline

Message Novembre 17th, 2008, 8:38 am

digitalMedia a écrit:
Vous avez besoin d'un RSS Parser. Si vous utilisez PHP, vous pouvez consulter Magpie...http://magpierss.sourceforge.net/


Bonjour DigitalMedia,

Merci pour le lien que vous avez fournies.
Le site que je voulais utiliser la météo est en html.

Merci encore,
Realty
  • ph81luc
  • Born
  • Born
  • No Avatar
  • Inscription: Nov 17, 2008
  • Messages: 3
  • Status: Offline

Message Novembre 17th, 2008, 11:04 am

Salut,

merci pour votre code, j'ai appliqué et de recevoir le message d'erreur suivant:
Capturables erreur fatale: Objet de la classe DOMNodeList ne pouvait pas être convertie en une chaîne de caractères dans / home/a2163261/public_html/weather.php sur la ligne 12

savez-vous d'où cela peut venir?

Merci!

Afficher de l'information

  • Total des messages de ce sujet: 9 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 128 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC