I am not sure I follow you - I guess I am not that familiar with the
"scheduler" - what is that?

What I ended up doing was - I have it go out and get the file via CFHTTP -
and then I save it to the server with cffile.  Then - for the next visitor
who comes, the pages checks the file via cfdirectory - to see if the file is
more than 3 hours old. If it is - it gets a new one - if not - it reads the
saved version.  (Code follows.)  If anyone has suggestions on improving it -
please let me know! It's the first time I have written anything like
this....  I think it works slick - but again - I'm a Noob.

Thanks!

-Nick

<!--- Get the RSS Feeds from the Database --->
<cfquery name="qryGetRSSFeeds" datasource="#datasource#">
SELECT *
FROM RSS
Where Active = "1"
Order by Sort
</cfquery>

<!--- Get the WebAddress from the Client Table --->
<cfquery name="qryGetClientWebaddress" datasource="#datasource#">
SELECT WebAddress
FROM Client
</cfquery>


<table cellpadding="4" cellspacing="2" border="0">
<tr>
<!--- --->
<!--- --->

<cfset TheRSSCFHTTPLink1 = "http://#qryGetClientWebaddress.WebAddress#";>



<!--- Output the RSS Feeds from the Database --->
<cfloop query="qryGetRSSFeeds">

                        <!--- Set RSS feeds next to eacother via table --->
                        <CFIF CurrentRow MOD 2 is 1>
                                </tr><tr><td valign="top">
                                <CFELSE>
                                <td valign="top">
                        </CFIF>



<!---  First: Setup the File Names Dynamically - based on the ACTIVE RSS
Feeds --->

                <cfset TheOrigRSSFile = "#qryGetRSSFeeds.Title#">
                <!---  Remove special characters client may have entered in the 
name --->
                        <cfset TheCleanedRSSFile = REReplace(TheOrigRSSFile, 
"[^0-9a-zA-Z_]",
"_", "ALL")>

                <cfset TheNewRSSFile = "#TheCleanedRSSFile#.xml">


<!---  Second: Check to See if the File Has been Saved on the Server --->

<cfif FileExists("#SiteRootDir#\rss\#TheNewRSSFile#")>

        <!--- File DOES Exist --->
                <cfdirectory
                        action="list"
                        name="RSSFile"
                        filter="#TheNewRSSFile#"
                        directory="#SiteRootDir#\rss\"
                        sort="Name">

                        <!--- Check the Date on the file --->
                        <!--- RenewDate: is file older than 3 hours? --->
                        <cfset RenewDate=dateAdd("h",-3,now())>

                                <cfif #RSSFile.dateLastModified# LTE 
#RenewDate#>
                                <!--- File IS old:Get New Feed  --->
                                        <!---First: Get Original Feed --->
                                                         <cfhttp 
url="#qryGetRSSFeeds.Link#" method="get">
                                        <!---No File: Write A New One! --->
                                        <cffile
                                                action="write"
                                                
file="#SiteRootDir#\rss\#TheNewRSSFile#"
                                                output="#cfhttp.filecontent#">
                                        </cffile>
                                        <!--- Set The Feed --->
                                        <cfset TheRSSCFHTTPLink2 = 
"#TheRSSCFHTTPLink1#/rss/#TheNewRSSFile#">
                                        <cfhttp url="#TheRSSCFHTTPLink2#" 
method="get">

                                <cfelse>
                                <!--- File Is OK: Use for Feed --->

                                        <!--- Set The Feed --->
                                        <cfset TheRSSCFHTTPLink2 = 
"#TheRSSCFHTTPLink1#/rss/#TheNewRSSFile#">
                                        <cfhttp url="#TheRSSCFHTTPLink2#" 
method="get">

                                </cfif>





<!--- FILE DOES NOT EXIST: Get New Feed! --->
<cfelse>


<!---No File: Write A New One! --->
<!---First: Get Original Feed --->
                 <cfhttp url="#qryGetRSSFeeds.Link#" method="get">
<!---Now write file --->
                <cffile
                        action="write"
                        file="#SiteRootDir#\rss\#TheNewRSSFile#"
                        output="#cfhttp.filecontent#">
                </cffile>
                                        <!--- Set The Feed --->
                                        <cfset TheRSSCFHTTPLink2 = 
"#TheRSSCFHTTPLink1#/rss/#TheNewRSSFile#">
                                        <cfhttp url="#TheRSSCFHTTPLink2#" 
method="get">

</cfif>


                        <cfoutput>

<!--- Out put of RSS code goes here--->
<p class="bodytext-header-4"><cfoutput>#qryGetRSSFeeds.Title#</cfoutput></p>
<cfset objRSS = xmlParse(cfhttp.filecontent)>
<!--- Validation flag --->
                                                <cfset XMLVALIDATION = true>

                                                <cftry>
                                                <!--- Create the XML object --->
                                                <cfset objRSS = 
xmlParse(cfhttp.filecontent)>

                                                <cfcatch type="any">
                                                <!--- If the document retrieved 
in the CFHTTP
                                                is not valid set the validation 
flag to false. --->
                                                <cfset XMLVALIDATION = false>
                                                </cfcatch>
                                                </cftry>

                                                <cfif XMLVALIDATION>
                                                <!--- If the validation flag is 
true continue parsing --->

                                                <!--- Set the XML Root --->
                                                <cfset XMLRoot = objRSS.XmlRoot>

                                                <!--- Retrieve the document 
META data --->
                                                <cfset doc_title = 
XMLRoot.channel.title.xmltext>
                                                <cfset doc_link = 
XMLRoot.channel.link.xmltext>
                                                <cfset doc_description = 
XMLRoot.channel.description.xmltext>

                                                                <!--- Output 
the meta data in the browser
                                                                <cfoutput>
                                                                <b>Title</b>: 
<a href="#doc_link#"
target="_blank">#doc_title#</a><br/>

                                                                
<b>Description</b>: #doc_description#<br/><br/>
                                                                </cfoutput>--->

                                                <!--- Retrieve the number of 
items in the channel --->
                                                <cfset Item_Length = 
arraylen(XMLRoot.channel.item)>

                                                <!--- Loop through all the items
                                                <cfloop index="itms" from="1" 
to="#Item_Length#">--->
                                                <!--- Loop through all My 
number of items --->
                                                <cfloop index="itms" from="1" 
to="#qryGetRSSFeeds.HowMany#">
                                                <!--- Retrieve the current Item 
in the loop --->
                                                <cfset tmp_Item = 
XMLRoot.channel.item[itms]>

                                                <!--- Retrieve the item data 
--->
                                                <cfset item_title = 
tmp_item.title.xmltext>
                                                <cfset item_link = 
tmp_item.link.xmltext>
                                                <cfset item_description = 
tmp_item.description.xmltext>
                                                <!--- See if Enclosure was 
defined --->
                                                <cfif 
IsDefined("tmp_Item.enclosure")>
                                                        <cfset 
item_enclosureURL = tmp_Item.enclosure.XmlAttributes.url>
                                                        <cfset 
item_enclosureType = tmp_Item.enclosure.XmlAttributes.type>
                                                </cfif>
                                                <!--- Output the items in the 
browser --->
                                                <cfoutput>
                                                <!--- Lists Item Number 
<b><i>Item #itms#</i></b><br/>--->
                                                        <!--- See if Enclosure 
was defined --->


                                                <p>
                                                <cfif 
IsDefined("tmp_Item.enclosure")>
                                                        <cfif 
#item_enclosureType# EQ "image/jpg">
                                                                <a 
href="#item_link#" target="_blank"><img src="#item_enclosureURL#"
title="#item_title#" border="0" align="left"></a>
                                                        </cfif>
                                                </cfif>
                                                <a href="#item_link#"
target="_blank">#item_title#</a><br/>#item_description#<br/><br/></p>





                                                </cfoutput>
                                                </cfloop>

                                                <cfelse>
                                                <!--- If the validation flag is 
false display error --->
                                                Invalid XML/RSS object!
                                                </cfif>




                        </cfoutput>

</td>


</cfloop>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:15:1758
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/15
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:15
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to