DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Getting And Parsing 10x10

05.17.2005
| 2490 views |
  • submit to reddit
        Here's my source code in ColdFusion for parsing 10x10. I can't imagine it being different in other languages.

----

<!--- build the wordsURL before getting the data --->
<cfset year = DateFormat(Now(),"YYYY")>
<cfset month = DateFormat(Now(),"MM")>
<cfset day = DateFormat(Now(),"DD")>
<cfset hour = TimeFormat(Now(),"HH")>
<cfset wordsURL = "http://tenbyten.org/Data/#year#/#month#/#day#/#hour#/words.txt">

<!--- connect to the url --->
<cfhttp method="get" url="#wordsURL#" timeout="60"></cfhttp>

<cfset wordlist = cfhttp.FileContent>

<!--- write the data into a text file --->
<cffile action="write" file="#ExpandPath('words.txt')#" output="#ToString(wordlist)#">

----

Reading the content is as simple as opening the file and traversing through it like so. I also added in a link to Google news. I've found it helpful to click on news bits in the past.

----

<cfhttp method="get" url="http://path/to/words.txt" timeout="60"></cfhttp>

<cfset wordlist = cfhttp.FileContent>

<ul><li>
<cfloop list="#wordlist#" delimiters="#chr(13)##chr(10)#" index="word">
  <cfoutput>
    <a href="http://news.google.com/news?q=#word#" target="_blank">#word#</a>
  </cfoutput>
</cfloop>
</li></ul>