Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for orin.vbs

(view source code of orin.vbs as plain text)

  1. ' =============================================
  2. ' ==    Modify the following 3 variables:    ==
  3. ' =============================================
  4.  
  5. ' Specify the URL and the output file's destination directory
  6. strURL = "http://www.orindaben.com/db/dbmeditation/meditation.php"
  7. strDir = "C:\My Documents\"
  8. ' The current week number will be appended to the file name specified here
  9. strFilePrefix = "Orin and DaBen meditation for week "
  10.  
  11. ' =============================================
  12. ' == Modify the 3 variables above this line! ==
  13. ' =============================================
  14.  
  15.  
  16. ' Check for command line arguments (none required)
  17. If WScript.Arguments.Count Then Syntax
  18.  
  19. ' Use our own error handling
  20. On Error Resume Next
  21.  
  22. ' Retrieve text from specified URL
  23. strText = TextFromHTML( strURL )
  24.  
  25. ' Get week number and append it to text file name
  26. numWeek = DatePart( "ww", Date,vbSunday,vbFirstFourDays )
  27. strFile = strDir & strFilePrefix & numWeek & ".txt"
  28.  
  29. ' Create a new text file
  30. Set fso        = CreateObject( "Scripting.FileSystemObject" )
  31. Set fileHandle = fso.CreateTextFile( strFile, True )
  32.  
  33. ' Write the retrieved text to the new file
  34. fileHandle.Write strText
  35.  
  36. ' Close the file
  37. fileHandle.Close
  38.  
  39. ' Use default text editor to display text read from URL
  40. Set wshShell = CreateObject( "WScript.Shell" )
  41. If Err Then ShowErr
  42. wshShell.Run( Quoted( strFile ) )
  43. If Err Then ShowErr
  44.  
  45. ' Normal program termination
  46. WScript.Echo 0
  47.  
  48.  
  49. Sub ShowErr
  50. 	strMsg = "Error # " & Err.Number & vbCrLf _
  51. 	       & Err.Description & vbCrLf & vbCrLf
  52. 	WScript.Echo strMsg
  53. End Sub
  54.  
  55.  
  56.  
  57. ' TextFromHTML() function by Rube Goldberg
  58. ' http://dev.remotenetworktechnology.com/wsh/rubegoldberg.htm
  59. Function TextFromHTML( URL )
  60. 	Set objIE = CreateObject( "InternetExplorer.Application" )
  61. 	If Err Then ShowErr
  62. 	objIE.Navigate URL
  63. 	If Err Then ShowErr
  64. 	Do Until objIE.ReadyState = 4
  65. 		WScript.Sleep 10
  66. 	Loop
  67. 	TextFromHTML = objIE.Document.Body.InnerText
  68. 	If Err Then ShowErr
  69. 	objIE.Quit
  70. End Function
  71.  
  72.  
  73. Function Quoted( str )
  74. 	Quoted = Chr(34) & str & Chr(34)
  75. End Function
  76.  
  77.  
  78. Sub Syntax
  79. 	strMsg = vbCrLf _
  80. 	       & "Orin.vbs,  Version 1.00" & vbCrLf _
  81. 	       & "Retrieve text from a URL and store it in a text file" & vbCrLf _
  82. 	       & "with the week number appended to its file name." _
  83. 	       & vbCrLf & vbCrLf _
  84. 	       & "Usage:  CSCRIPT  ORIN.VBS" _
  85. 	       & vbCrLf & vbCrLf _
  86. 	       & "I wrote this script for my wife, so she can automatically retrieve the" & vbCrLf _
  87. 	       & "text for a weekly meditation by Orin and DaBen and store it for later use." & vbCrLf _
  88. 	       & "That is why the week number is appended to the destination file name." & vbCrLf _
  89. 	       & "The URL and the destination of the text are hard coded into this script." & vbCrLf _
  90. 	       & "Adapt them to your own needs." _
  91. 	       & vbCrLf & vbCrLf _
  92. 	       & "The function to retrieve text from a URL was written by Rube Goldberg" & vbCrLf _
  93. 	       & "http://dev.remotenetworktechnology.com/wsh/rubegoldberg.htm" _
  94. 	       & vbCrLf & vbCrLf _
  95. 	       & "Written by Rob van der Woude" & vbCrLf _
  96. 	       & "http://www.robvanderwoude.com"
  97. 	WScript.Echo strMsg
  98. 	Wscript.Quit 1
  99. End Sub
  100.  

page last uploaded: 2018-12-04, 10:47