March 11, 2010

Pages


Search Site


Topics



Archives

Entries Tagged as 'BlogCFC Pod Goodies'

NYMEX Crude Oil Pod

October 22 2008 by admin
Its been a while since I had a new post. Mainly because I've been working on an awesome Flex application for the Fleet Leasing Company where I work. About 3 months ago I got a Yahoo Widget that reads the NYMEX for Light Sweet Crude and posts the price to my desktop ever 20 minutes or so. The owner of my company comes over a couple times a week and checks it out. Today he asked me to create one for our client website. So the cfc I made now drives the pod. Here is the code:
The CFC
<cfcomponent>
   <cffunction name="getOilPrice" access="public" returntype="string">
      <cfargument name="firstCatch" type="string" default="#HTMLEditFormat('<span class="tbl_num">')#">
<cfargument name="lastCatch" type="string" default="#HTMLEditFormat('</span>')#">
      <cfargument name="crudeURL" type="string" default="http://www.bloomberg.com/markets/commodities/energyprices.html">
<cfhttp url="#arguments.crudeURL#" resolveurl="Yes" throwOnError="Yes"/>
         <cfset nymex = #CFHTTP.FileContent#>
<cfset firstDmp = '#mid(nymex, 1, val(find(arguments.firstCatch, nymex, 0) + val(len(arguments.firstCatch)-1)))#'>
         <cfset leftNYMEX = ReplaceNoCase(nymex, firstDmp, '')>
<cfset secondDmp = '#mid(leftNYMEX, 1, val(find('.', leftNYMEX, 0) + 2))#'>
<cfset newNYMEX = secondDmp>
      <cfreturn newNYMEX>
   </cffunction>
</cfcomponent>
The Pod
<cfsetting enablecfoutputonly='true'>
<cfprocessingdirective pageencoding='utf-8'>
<!---
Name : NYMEX Crude Oil Price
Author : PodGenerator (based on archives.cfm by Raymond Camden)
--->


<cfmodule template='../../tags/podlayout.cfm' title='NYMEX Crude Oil Price'>
<!---
Your Pod text goes here -
Remember it has to be in cfoutput
tags or it will not be displayed
--->
<cfinvoke component="components.nymex" method="getOilPrice" returnvariable="newNYMEX">
   <cfinvokeargument name="firstCatch" value='<span class="tbl_num">'>
<cfinvokeargument name="lastCatch" value='</span>'>
<cfinvokeargument name="crudeURL" value="http://www.bloomberg.com/markets/commodities/energyprices.html">
</cfinvoke>
<cfoutput>
<div align="center">NYMEx Crude Oil Price as of:</div>
<div align="center">#dateFormat(now(), 'mmm/dd/yy')# #timeFormat(now(), 'HH:MM')#</div>
<div align="center">#dollarFormat(newNYMEX)#</div>
</cfoutput>      
</cfmodule>
<cfsetting enablecfoutputonly='false'/>
Feel free to use it, but don't be like Ray Horn and not pay homage to my greatness. Created by Christopher Walker - www.SharedDynamics.com

Posted in BlogCFC Pod Goodies | 5 comments