Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for birdname.bat

(view source code of birdname.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5.  
  6. :: Enable delayed variable expansion
  7. SETLOCAL ENABLEDELAYEDEXPANSION
  8.  
  9.  
  10. :: Check command line argument(s)
  11. IF "%~1"=="" GOTO Syntax
  12. ECHO.%* | FIND "?" >NUL && GOTO Syntax
  13.  
  14.  
  15. :: Check if FINDSTR is available
  16. FINDSTR /? 2>&1 | FIND "/B" >NUL || GOTO Syntax
  17.  
  18. :: Check if WGetTxt.vbs is available
  19. SET WGetTxt=
  20. SET Download=
  21. SET Search="%CD%;%PATH%"
  22. SET Search=%!!%
  23. FOR %%A IN (%Search%) DO (
  24. 	IF "!WGetTxt!"=="" (
  25. 		IF NOT "%%~A"=="" (
  26. 			IF EXIST "%%~A.\WGetTxt.vbs" (
  27. 				PUSHD "%%~fA"
  28. 				SET WGetTxt="!__CD__!WGetTxt.vbs"
  29. 				POPD
  30. 			)
  31. 		)
  32. 	)
  33. )
  34. :: Prompt for download if WGetTxt is not found
  35. IF "%WGetTxt%"=="" (
  36. 	ECHO This batch file requires the WGetTxt.vbs script.
  37. 	SET /P Download=Do you want to download it now? [y/N] 
  38. )
  39. :: Start download if confirmed
  40. IF /I "%Download%"=="Y" (
  41. 	START /WAIT http://www.robvanderwoude.com/files/wget.zip
  42. 	ECHO.
  43. 	ECHO UnZIP WGetTxt.vbs from the downloaded ZIP file, either to the current
  44. 	ECHO directory or to a directory listed in the PATH; then try again.
  45. )
  46. :: Abort if WGetTxt.vbs is not available yet
  47. IF "%WGetTxtAvailable%"=="No" GOTO End
  48.  
  49.  
  50. SET BirdName.Dutch=%*
  51. SET _BirdName.Dutch=%BirdName.Dutch: =_%
  52. SET BirdName.Danish=
  53. SET BirdName.English=
  54. SET BirdName.French=
  55. SET BirdName.German=
  56. SET BirdName.Scientific=
  57. FOR /F "tokens=2 delims=()" %%A IN ('CSCRIPT.EXE //NoLogo %WGetTxt% /U:http://nl.wikipedia.org/wiki/%_BirdName.Dutch% ^| FINDSTR /R /I /C:"%BirdName.Dutch% ([^^)]*) is"') DO (
  58. 	IF "!BirdName.Scientific!"=="" SET BirdName.Scientific=%%A
  59. )
  60. IF NOT DEFINED BirdName.Scientific (
  61. 	FOR /F "tokens=2 delims=()" %%A IN ('CSCRIPT.EXE //NoLogo %WGetTxt% /U:http://nl.wikipedia.org/wiki/%_BirdName.Dutch% ^| FINDSTR /R /I /C:"%BirdName.Dutch% ([^^)]*) behoort"') DO (
  62. 		IF "!BirdName.Scientific!"=="" SET BirdName.Scientific=%%A
  63. 	)
  64. )
  65. ECHO.%BirdName.Scientific% | FIND "," >NUL && FOR /F "delims=," %%A IN ("%BirdName.Scientific%") DO SET BirdName.Scientific=%%A
  66. ECHO.%BirdName.Scientific% | FIND "[" >NUL && FOR /F "delims=[" %%A IN ("%BirdName.Scientific%") DO SET BirdName.Scientific=%%A
  67. SET _BirdName.Scientific=%BirdName.Scientific: =_%
  68. FOR /F "tokens=*" %%A IN ('CSCRIPT.EXE //NoLogo %WGetTxt% /U:http://da.wikipedia.org/wiki/%_BirdName.Scientific% ^| FIND /V "[CDATA[" ^| FIND /V "." ^| FIND /V ""') DO (
  69. 	IF "!BirdName.Danish!"=="" SET BirdName.Danish=%%A
  70. )
  71. FOR /F "tokens=*" %%A IN ('CSCRIPT.EXE //NoLogo %WGetTxt% /U:http://en.wikipedia.org/wiki/%_BirdName.Scientific% ^| FIND /V "[CDATA[" ^| FIND /V "." ^| FIND /V ""') DO (
  72. 	IF "!BirdName.English!"=="" SET BirdName.English=%%A
  73. )
  74. FOR /F "tokens=*" %%A IN ('CSCRIPT.EXE //NoLogo %WGetTxt% /U:http://fr.wikipedia.org/wiki/%_BirdName.Scientific% ^| FIND /V "[CDATA[" ^| FIND /V "." ^| FIND /V ""') DO (
  75. 	IF "!BirdName.French!"=="" SET BirdName.French=%%A
  76. )
  77. FOR /F "tokens=*" %%A IN ('CSCRIPT.EXE //NoLogo %WGetTxt% /U:http://de.wikipedia.org/wiki/%_BirdName.Scientific% ^| FIND /V "[CDATA[" ^| FIND /V "." ^| FIND /V ""') DO (
  78. 	IF "!BirdName.German!"=="" SET BirdName.German=%%A
  79. )
  80. SET BirdName.
  81. ENDLOCAL
  82. GOTO:EOF
  83.  
  84.  
  85. :Syntax
  86. ECHO.
  87. ECHO BirdName.bat,  Version 0.31 beta
  88. ECHO Get scientific and some translated names for a specified Dutch bird name
  89. ECHO.
  90. ECHO Usage:  BIRDNAME  dutch bird name
  91. ECHO.
  92. ECHO Notes:  Do NOT use quotes for the Dutch bird name.
  93. ECHO         Specified bird names must be complete, e.g. "Middelste Zaagbek" instead
  94. ECHO         of just "Zaagbek" (do NOT use the quotes on the command line).
  95. ECHO         This batch file requires WGetTxt.vbs to get information from Wikipedia;
  96. ECHO         if WGetTxt.vbs is not found, you will be prompted to download it.
  97. ECHO         It also requires FINDSTR, which is not native in Windows NT 4.
  98. ECHO         Translations include Danish, English, French, German and scientific;
  99. ECHO         support for Spanish could not be included yet, because WikiPedia Spain
  100. ECHO         uses the scientific name for the page title.
  101. ECHO         This batch file will break when WikiPedia changes its page layout.
  102. ECHO.
  103. ECHO Written by Rob van der Woude
  104. ECHO http://www.robvanderwoude.com
  105.  
  106. :End
  107. IF "%OS%"=="Windows_NT" ENDLOCAL
  108. IF "%OS%"=="Windows_NT" EXIT /B 1
  109.  

page last uploaded: 2016-12-15, 11:20