AndyJarrett

RSS weather CFC

You most likely didn't notice but i have a new "pod" called "Weather". I got the idea this morning after reading this post at Flex-MX. Its generated from a RSS feed from RSSWeather.com. If you want the code you can download it here or its below for you if you click on "more"
<cfcomponent hint="Return the weather">
   <!---
      Author:       Andy Jarrett - mail@andyjarrett.co.uk
      Created:      20/08/04
      Desciption: Returns the weather for you area from a RSS feed
   --->
      
   <cffunction name="myWeather" returntype="struct" hint="Returns the weather from http://www.rssweather.com" >
      <!--- Basic vars needed --->

      <cfset var weatherRss = "http://www.rssweather.com/rss.php?config=&forecast=zandh&icao=EGHI&alt=rss20a">
      <cfset var weatherXML = "">
      <cfset var weatherToday = structNew()>
            
      <cfif NOT isDefined("application.weatherXML.lastParsed") OR NOW() GT dateAdd("H", 3, application.weatherXML.lastParsed)>
         <!--- Get feed --->
         <cfhttp url="#weatherRss#" method="GET"></cfhttp>
         <!--- You need to know the reason it was last parsed because you will get banned if you hit several times within the hour. --->
         <cfset application.weatherXml.lastParsed = NOW()>
         <cfset application.weatherXml.parsed = xmlParse(cfhttp.filecontent)>
      </cfif>
      
      <cfscript>
         weatherXML = application.weatherXml.parsed;
         weatherToday.text = weatherXML.rss.channel.item.description.xmlText;
         weatherToday.link = weatherXML.rss.channel.item.link.xmlText;
      </cfscript>
      
      <cfreturn weatherToday>
   </cffunction>   
</cfcomponent>