Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for youlessbar.bat

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

  1. @ECHO OFF
  2. SETLOCAL ENABLEDELAYEDEXPANSION
  3.  
  4. ProgressBar.exe /? >NUL 2>&1
  5. IF %ErrorLevel% NEQ -1 (
  6. 	ECHO.
  7. 	ECHO ERROR: ProgressBar.exe not found
  8. 	ECHO.
  9. 	GOTO Syntax
  10. )
  11.  
  12. wget.exe >NUL 2>&1
  13. IF %ErrorLevel% NEQ 1 (
  14. 	ECHO.
  15. 	ECHO ERROR: wget.exe not found
  16. 	ECHO.
  17. 	GOTO Syntax
  18. )
  19.  
  20. SET Interval=5
  21. SET Scale=
  22.  
  23. IF NOT "%~2"=="" GOTO Syntax
  24. IF NOT "%~1"=="" (
  25. 	ECHO."%~1"| FINDSTR.EXE /R /X /C:".[0-9][0-9]*." >NUL
  26. 	IF ERRORLEVEL 1 (
  27. 		GOTO Syntax
  28. 	) ELSE (
  29. 		SET Interval=%~1
  30. 	)
  31. )
  32.  
  33. IF %Interval% LSS   1 GOTO Syntax
  34. IF %Interval% GTR 120 GOTO Syntax
  35.  
  36.  
  37. FOR /F "tokens=2 delims=:" %%A IN ('MODE CON: ^| FIND.EXE ":" ^| FIND.EXE /N ":" ^| FIND.EXE "[3]"') DO (
  38. 	REM Remove leading and trailing spaces
  39. 	FOR %%B IN (%%A) DO SET ConsoleWidth=%%B
  40. )
  41.  
  42. CLS
  43. ECHO.
  44. ECHO.
  45. ECHO.
  46.  
  47. :: Center text
  48. SET /A StartPos = %ConsoleWidth% / 2 - 11
  49. FOR /L %%A IN (1,1,%StartPos%) DO (
  50. 	SET /P "=^ " < NUL
  51. )
  52. ECHO Youless power monitor
  53.  
  54. :: Underline centered text
  55. SET /A StartPos = %ConsoleWidth% / 2 - 11
  56. FOR /L %%A IN (1,1,%StartPos%) DO (
  57. 	SET /P "=^ " < NUL
  58. )
  59. ECHO.=====================
  60.  
  61. ECHO.
  62. ECHO.
  63.  
  64. :Start
  65.  
  66. :: Get actual logging values
  67. FOR /F "tokens=1 delims={}[]" %%A IN ('WGET.EXE -q -O - http://youless/e') DO (SET AllValues=%%A)
  68.  
  69. :: Store collected values in environment variables
  70. SET RemainingValues=%DeviceData%,%AllValues%
  71. :Loop
  72. FOR /F "tokens=1* delims=," %%A IN ("!RemainingValues!") DO (
  73. 	FOR /F "tokens=1* delims=:" %%C IN ('ECHO %%A') DO (
  74. 		SET Values.%%~C=%%~D
  75. 		REM Format date and time to make it more readable
  76. 		IF "%%~C"=="gts" (
  77. 			SET Values.%%~C=20!Values.%%~C:~0,2!-!Values.%%~C:~2,2!-!Values.%%~C:~4,2! !Values.%%~C:~6,2!:!Values.%%~C:~8,2!
  78. 		)
  79. 		REM make uppercase and replace colons by dashes
  80. 		IF "%%~C"=="mac" (
  81. 			SET Values.%%~C=!Values.%%~C::=-!
  82. 			SET Values.%%~C=!Values.%%~C:a=A!
  83. 			SET Values.%%~C=!Values.%%~C:b=B!
  84. 			SET Values.%%~C=!Values.%%~C:c=C!
  85. 			SET Values.%%~C=!Values.%%~C:d=D!
  86. 			SET Values.%%~C=!Values.%%~C:e=E!
  87. 			SET Values.%%~C=!Values.%%~C:f=F!
  88. 		)
  89. 		REM Remove leading spaces
  90. 		FOR /F "tokens=*" %%E IN ("!Values.%%~C!") DO SET Values.%%~C=%%E
  91. 	)
  92. 	IF "%%~B"=="" GOTO EndLoop
  93. 	SET RemainingValues=%%B
  94. 	GOTO Loop
  95. )
  96. :EndLoop
  97.  
  98. ProgressBar.exe %Values.pwr% -2000 2000 Yellow Green %Scale%
  99. IF ERRORLEVEL 1 (
  100. 	ENDLOCAL
  101. 	EXIT /B 1
  102. )
  103.  
  104. SET Scale=/NS
  105.  
  106. :: Wait a number of seconds
  107. Timeout.exe /T %Interval% >NUL
  108. GOTO :Start
  109.  
  110. :End
  111. ENDLOCAL
  112. EXIT /B 0
  113.  
  114.  
  115. :Syntax
  116. ECHO.
  117. ECHO YoulessBar.bat,  Version 1.00
  118. ECHO Read data from a Youless LS120 device and show result in a progress bar
  119. ECHO.
  120. ECHO Usage:    Youless.exe  [ seconds ]
  121. ECHO.
  122. ECHO Where:    seconds      interval between log queries (1..120)
  123. ECHO.
  124. ECHO Notes:    This program requires wget.exe, available at:
  125. ECHO           https://gnuwin32.sourceforge.net/packages/wget.htm
  126. ECHO           and ProgressBar.exe, available at:
  127. ECHO           https://www.robvanderwoude.com/files/progressbar.zip
  128. ECHO           Return code ("ErrorLevel") equals 1 in case of
  129. ECHO           (command line) errors, otherwise 0.
  130. ECHO.
  131. ECHO Written by Rob van der Woude
  132. ECHO https://www.robvanderwoude.com
  133.  
  134. ENDLOCAL
  135. EXIT /B 1
  136.  

page last modified: 2024-04-16; loaded in 0.0066 seconds