Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: IReadData Weather report historical
;*************************************************************************** ;** WeatherWatch.wbt ;** Get Historical Weather information ;** ;** Purpose: Gather weather info for cities from www.wunderground.com ;** Inputs: date in YYYY:MM:DD format ;** Outputs: File- 'weather{date}.txt' ;** Revisions: 1.0 ;** Scripting Language: (WinBatch) Windows Interface language ;** Author: Deana Dahley 01.12.2006 ;*************************************************************************** #DefineSubroutine MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_ID,MyDialog_EventInfo,rsvd) MSG_INIT=0 RET_DO_DEFAULT= -1 ; Continue with default processing for control DLGOBJECT_GETOBJECT=3 ; Return an object references to the specified control switch MyDialog_Message ; Switch based on Dialog Message type case MSG_INIT ; Standard Initialization message ;Get the control's object objHtmlDoc = DialogObject(MyDialog_Handle, 003, DLGOBJECT_GETOBJECT) objHtmlDoc.write('<HTML><HEAD><TITLE>WeatherWatch</TITLE></HEAD><BODY>') objHtmlDoc.write(tabledata) objHtmlDoc.write('</BODY></HTML>') return(RET_DO_DEFAULT) endswitch ; MyDialog_Message return(RET_DO_DEFAULT) #Endsubroutine ; End of Dialog Callback MyDialogCallbackProc ;specify city where = "KBFI"; city = "Seattle, WA" ;where = "KLAX" ;city = "Los Angeles, CA" ;where = "KDAL" ;city = "Dallas, TX" ;where = "KLGA"; ;city = "New York, NY" ;where = "PHJH" ;city = "Lahaina, HI" :dddialog PromptDialogFormat=`WWWDLGED,6.1` PromptDialogCaption=`Get Historical Weather Conditions` PromptDialogX=078 PromptDialogY=078 PromptDialogWidth=203 PromptDialogHeight=182 PromptDialogNumControls=010 PromptDialogProcedure=`DEFAULT` PromptDialogFont=`Book Antiqua|8192|70|18` PromptDialogTextColor=`DEFAULT` PromptDialogBackground=`DEFAULT,DEFAULT` PromptDialogConfig=0 PromptDialog001=`036,137,048,011,PUSHBUTTON,DEFAULT,"OK",1,1,32,DEFAULT,DEFAULT,DEFAULT` PromptDialog002=`089,079,035,011,EDITBOX,year,"2000",DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` PromptDialog003=`089,095,035,011,EDITBOX,month,"01",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` PromptDialog004=`089,111,035,011,EDITBOX,day,"01",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT` PromptDialog005=`049,079,035,011,STATICTEXT,DEFAULT,"Year:",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT` PromptDialog006=`049,111,035,011,STATICTEXT,DEFAULT,"Day:",DEFAULT,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT` PromptDialog007=`049,095,035,011,STATICTEXT,DEFAULT,"Month:",DEFAULT,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT` PromptDialog008=`009,023,182,019,STATICTEXT,DEFAULT,"Input date that you want conditions for..",DEFAULT,8,512,DEFAULT,"0|0|0",DEFAULT` PromptDialog009=`074,063,051,011,VARYTEXT,city,"Some City",DEFAULT,9,DEFAULT,DEFAULT,DEFAULT,DEFAULT` PromptDialog010=`092,137,046,011,PUSHBUTTON,DEFAULT,"Cancel",0,10,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("PromptDialog") ;Load the WinInet extender AddExtender("WWINT34I.DLL") ; The host name is the first part of the URL, minus the http:// host="www.wunderground.com" ;Handle user input ;make sure month is single digit if start with zero len=strlen(month) if len>1 char=strsub(month,1,1) if char==0 month=strsub(month,2,1) endif endif date = StrCat(month,"/",day,"/",year) ;Part of the URL we wish to GET is *everything* after the host name geturl="history/airport/%Where%/%year%/%month%/%day%/DailyHistory.html" ;Make sure to allocate large enough buffer to hold the entire webpage size=100000 buf=BinaryAlloc(size) ;Get address of binary buffer bufaddr=IntControl (42, buf, 0, 0, 0) BinaryEodSet(buf,0) ; Basic web page fetch tophandle=iBegin(0,"","") connecthandle=iHostConnect(tophandle, host, @HTTP, "", "") datahandle=iHttpInit(connecthandle,"GET",geturl,"", 0) rslt = iHttpOpen(datahandle, "", 0, 0); if rslt=="ERROR" || rslt!=200 if rslt == "ERROR" errstr = "WinInet Error" rslt = iGetLastError() else errstr = "HTTP Error" endif Message(errstr,rslt) iClose(tophandle) exit endif rslt=iReadDataBuf(datahandle,bufaddr,size) if rslt == 0 Message("Error", "Problem retrieving the data.") Binaryfree(buf) exit ;Give up endif BinaryEodSet(buf,rslt) iClose(datahandle) iClose(connecthandle) iClose(tophandle) retry = 0 begptr = BinaryIndexEx( buf, 0, "Daily Summary", @FWDSCAN ,0);find 'Daily Summary' if begptr == -1 Message("No historial information found!", "Check the date.%@Crlf%- Make sure the date input is valid%@CRLF%- Not today's date or a future date") Binaryfree(buf) retry = 1 endif if retry == 1 then Goto dddialog ;find beginning of table begptr = BinaryIndexEx( buf,begptr, '<table', @BACKSCAN ,0) if begptr == -1 Message("Error", "Problem retrieving table data.") Binaryfree(buf) exit ;Give up endif ;find end of table endptr = BinaryIndexEx( buf,begptr+1, '</table>', @FWDSCAN ,0) if endptr == -1 Message("Error", "Problem retrieving table data.") Binaryfree(buf) exit ;Give up endif endptr = endptr+8 tabledata = BinaryPeekStr(buf, begptr, endptr-begptr) ;Display table of data MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`Weather Watch` MyDialogX=002 MyDialogY=040 MyDialogWidth=492 MyDialogHeight=339 MyDialogNumControls=005 MyDialogProcedure=`MyDialogCallbackProc` MyDialogFont=`Book Antiqua|8192|70|18` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`199,308,048,011,PUSHBUTTON,DEFAULT,"OK",1,1,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`270,308,047,011,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`012,052,465,248,COMCONTROL,DEFAULT,"mshtml:",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`014,036,460,011,VARYTEXT,Date,DEFAULT,DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog005=`014,020,458,011,VARYTEXT,City,DEFAULT,DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") ;free buffers BinaryFree(buf) exit
Article ID: W14441
Filename: Sample code - Weather Watch.txt
File Created: 2006:01:12:09:21:22
Last Updated: 2006:01:12:09:21:22