' ---------------------------------------------------------------- ' __ _ ' / _| | ' _ __ ___ _ _ ___ ___ | |_| |_ '| '_ ` _ \| | | | / __|/ _ \| _| __| '| | | | | | |_| |_\__ \ (_) | | | |_ '|_| |_| |_|\__, (_)___/\___/|_| \__| ' __/ |http://myDotSoft.com ' |___/ ' ---------------------------------------------------------------- ' title : my.GasBuddy ' filename : my.gasbuddy.txt ' version : 0.3 ' description : report preferred station using GasBuddy.com data ' author : Dan (electron) ' email : dan at marstracker dot org ' ---------------------------------------------------------------- ' DISCLAIMER ' ---------------------------------------------------------------- ' my.GasBuddy is freeware, however, it is NOT in the Public Domain and ' my.Soft retains the copyright for this work. You can use my.GasBuddy ' freely, but you can not claim it as your own creation, or charge ' others money for it. ' Use my.GasBuddy at your own risk. This script is provided for your own ' personal use, as is. Any commercial use is strictly prohibited. ' my.Soft, or the author, shall not be held responsible for any ' results allegedly caused by use (or misuse) of this script. ' ---------------------------------------------------------------- ' Instructions : ' [1] Copy this script to the Homeseer scripts directory. ' [2] Go to the GasBuddy.com site, pick your local GasBuddy site, ' and 'search' for your gas station. Try to narrow down the ' search as much as possible by specifying an Area and the ' type of gas station (you want to avoid your preferred station ' not showing up in the list). ' [3] Set the variables in the 'User definable Settings' section, ' follow the provided example. ' ---------------------------------------------------------------- ' changelog: ' ' version 0.3 (09032005): include 'last updated' timestamp ' version 0.2 (09032005): due to complex HTML code, switched code ' to use regular expressions ' version 0.1 (09012005): created script ' ---------------------------------------------------------------- ' Public sSite,sDevicePref,bDebug,sPreferredStationName,sPreferredStationAddress,sPreferredStationArea,sPage,sPattern ' sub main() ' ' ---------------------------------------------------------------- ' User definable settings ' ---------------------------------------------------------------- ' ' Which Homeseer virtual device do you want to use to report the current gas price sDevicePref = "v12" ' ' ' Regular expressions matches are used, so you can use a RE syntax if required ' (very useful if the address spelling changes frequently, etc.) ' sPreferredStationName = "Mobil" sPReferredStationArea = "Central Square" sPreferredStationAddress = "Rt 49 & Rt 11" ' sSite = "syracusegasprices.com" sPage = "/index.aspx?s=Y&fuel=A&area=Central%20Square&station=All%20Stations&tme_limit=84" ' bDebug = true ' ' ---------------------------------------------------------------- ' Do not modify anything below unless you know what you are doing! ' ---------------------------------------------------------------- sPattern = ".*update_form.aspx\?pid=\d+\'>(\d\.\d+).*" & sPreferredStationName & ".*" & sPreferredStationArea & ".*(Mon|Tue|Wed|Thu|Fri|Sat|Sun)
(\d+\:\d+\s(AM|PM)).*" & sPreferredStationAddress & ".*" ' sData = hs.GetUrl(sSite,sPage,false,80) sData = Replace(sData, chr(9), "",1,-1,1) sData = Replace(sData, chr(10),"",1,-1,1) sData = Replace(sData, chr(13), "",1,-1,1) If sData = "" Or Instr(1,sData,"an error",1) Then e "Unable to download data from " & sSite d Sdata Exit Sub Else d sData If Instr(1,sData,sPreferredStationAddress,1) Then Set objRegEx = New RegExp objRegEx.IgnoreCase = True objRegEx.Pattern = sPattern sData = objRegEx.Replace(sData,"$1 $2 $3") d sData hs.SetDeviceString sDevicePref,"$" & Mid(sData,1,4) & " per gallon. (Last updated: " & Mid(sData,5) & ")",TRUE hs.SetDeviceValue sDevicePref, Mid(sData,1,4) * 100 If hs.DeviceValue(sDevicePref) <> Mid(sData,1,4) * 100 Then d "Price change has been detected, old price was " & hs.DeviceValue(sDevicePref) / 100 & ", new price is " & sData Else d "No price change has been detected" End If Else d "preferred gas station is not on the list" Exit Sub End If End If d sSite & " reports $" & Mid(sData,1,4) & "/gallon for your preferred gas station" end sub Sub d(sText) If bDebug = true Then hs.writelog "my.GasBuddy:debug", sText End If End Sub Sub e(sText) hs.writelog "my.GasBuddy:error", sText End Sub