RSS weather CFC
<cfcomponent hint="Return the weather">
<!---
Author: Andy Jarrett - [email protected]
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>
<!---
Author: Andy Jarrett - [email protected]
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>