Advertisement
EzFlow997

ReadErrors Checker

Mar 18th, 2025
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 8.98 KB | Source Code | 0 0
  1. #NoEnv
  2. #Warn
  3. #SingleInstance Force
  4. SetWorkingDir %A_ScriptDir%
  5. SetBatchLines -1
  6.  
  7. FileDelete, ReadErrors.html
  8. global readPerc := 1
  9. global PercentInputBool := 0
  10.  
  11. global PCX_List_Array := [ ]
  12. Loop, Read, PCX_List.txt
  13.     PCX_List_Array.Push(A_LoopReadLine)
  14.    
  15. global test_ip := PCX_List_Array[1]
  16. global connectionTestStatus := 0
  17.  
  18. Hotkey, ^1, Exit
  19. Hotkey, ^!5, PercentInputStatus
  20.  
  21. ReadConfig(){
  22.     IniRead, readPerc, config.ini, Settings, ReadErrorPercent
  23.     if(readPerc = "ERROR"){
  24.         readPerc := 1
  25.     }
  26. }
  27.  
  28. WriteConfig(){
  29.     IniWrite, %readPerc%, config.ini, Settings, ReadErrorPercent
  30. }
  31.  
  32. PercentInputStatus(){
  33.     PercentInputBool := 1
  34. }
  35.  
  36. PercentInput(){
  37.     InputBox, readPerc, Percent Check, `% = %readPerc%`nNew Input :,,,,,,10
  38.     if(readPerc/1 != readPerc or readPerc < 0 or readPerc > 100){
  39.         readPerc := 1
  40.     }
  41.     WriteConfig()
  42.     Sleep, 1000
  43. }
  44.  
  45. ConnectionTest(){
  46.     if(connectionTestStatus = 0){
  47.         connectionTestStatus := 1
  48.         FileDelete, connectTest.bat
  49.         FileDelete, ConnectTest.txt
  50.         FileAppend, ping -n 4 -w 500 %test_ip%>ConnectTest.txt, connectTest.bat
  51.         Run, connectTest.bat,,Hide,pID
  52.         Loop,{
  53.             Process, Exist, %pID%
  54.             if(ErrorLevel = 0){
  55.                 break
  56.             }
  57.         }
  58.         tL := ""
  59.         FileReadLine, tL, ConnectTest.txt, 9
  60.         if not(InStr(tL, "Received = 4", true, 1) > 0){
  61.             MsgBox,,ERROR, No Connection to PCX, 3
  62.             Exit()
  63.         }
  64.         else{
  65.             DownloadingScannerReads()
  66.             SetTimer, ConnectionTest, 15000
  67.         }
  68.         FileDelete, connectTest.bat
  69.         FileDelete, ConnectTest.txt
  70.         connectionTestStatus := 0
  71.     }
  72. }
  73.  
  74. Exit(){
  75.     if(PercentInputBool = 1){
  76.         PercentInput()
  77.     }
  78.     FileDelete, connectTest.bat
  79.     FileDelete, ConnectTest.txt
  80.     ExitApp
  81. }
  82.  
  83. DownloadingScannerReads(){
  84.     SetWorkingDir %A_ScriptDir%/pcxLogs
  85.     xPos := A_ScreenWidth*3.2/4.0
  86.     yPos := A_ScreenHeight*0.3/4.0
  87.     Progress, b w200 x%xPos% y%yPos%, , Downloading..., Loading Bar
  88.     pInd := 0
  89.     MaxVal := PCX_List_Array.MaxIndex()
  90.  
  91.     Loop % PCX_List_Array.MaxIndex(){
  92.         pcxNum := A_Index
  93.         pcx_address := PCX_List_Array[A_Index]
  94.         UrlDownloadToFile, http://%pcx_address%/station/index.html, PCX_%pcxNum%.txt
  95.         pInd += (100/MaxVal)
  96.         Progress, %pInd%
  97.     }
  98.     Progress, Off
  99.  
  100.     SetWorkingDir %A_ScriptDir%
  101.  
  102.     textVar1=
  103.     (
  104.     <style type="text/css">
  105.     .tg  {border-collapse:collapse;border-color:#aaa;border-spacing:0;}
  106.     .tg td{background-color:#fff;border-color:#aaa;border-style:solid;border-width:1px;color:#333;
  107.       font-family:Arial, sans-serif;font-size:14px;overflow:hidden;padding:8px 13px;word-break:normal;}
  108.     .tg th{background-color:#f38630;border-color:#aaa;border-style:solid;border-width:1px;color:#fff;
  109.       font-family:Arial, sans-serif;font-size:14px;font-weight:normal;overflow:hidden;padding:8px 13px;word-break:normal;}
  110.     .tg .tg-xyoc{font-family:"Arial Black", Gadget, sans-serif !important;font-size:18px;font-weight:bold;text-align:center;
  111.       vertical-align:middle}
  112.       .tg .tg-xyod{font-family:"Arial Black", Gadget, sans-serif !important;font-size:26px;font-weight:bold;text-align:center;
  113.       vertical-align:middle}
  114.         .tg .tg-xyop{color:#5179aa;font-family:"Arial Black", Gadget, sans-serif !important;font-size:72px;font-weight:bold;text-align:center;
  115.       vertical-align:middle}
  116.     .tg .tg-vqva{background-color:#f5e6e6;border-color:inherit;font-family:"Arial Black", Gadget, sans-serif !important;font-size:14px;
  117.       text-align:center;vertical-align:middle}
  118.     .tg .tg-dibh{background-color:#f5e6e6;border-color:inherit;color:#fe0000;font-family:"Arial Black", Gadget, sans-serif !important;
  119.       font-size:14px;text-align:center;vertical-align:middle}
  120.     </style>
  121.  
  122.     <h1 style="text-align: center;"><a title='PCX Scanners List' href='file:///%A_ScriptDir%/scannerList.pdf' target="_blank"><span class="tg"><em class="tg-xyop">
  123.     <strong> - PCX SCANNERS - </strong> </em></span></a></h1>
  124.     )
  125.  
  126.     FileAppend, %textVar1%`n, ReadErrors.html
  127.     SetWorkingDir %A_ScriptDir%/pcxLogs
  128.  
  129.     fileName := ""
  130.     addressName := ""
  131.  
  132.     xPos := A_ScreenWidth*3.2/4.0
  133.     yPos := A_ScreenHeight*0.3/4.0
  134.     Progress, b w200 x%xPos% y%yPos%, , Reading..., Loading Bar
  135.     pInd := 0
  136.  
  137.     Loop % PCX_List_Array.MaxIndex(){
  138.         pcxNum := A_Index
  139.         fileName = PCX_%pcxNum%.txt
  140.         pcx_address := PCX_List_Array[A_Index]
  141.         addressName = http://%pcx_address%
  142.         ;MsgBox, %fileName%
  143.        
  144.         pcxFileLine := 50
  145.         pcxHeader:=0
  146.         endTable:=0
  147.         Loop{
  148.             ;MsgBox, %pcxFileLine%
  149.             FileReadLine, line, %fileName%, %pcxFileLine%
  150.             if (ErrorLevel != 0){
  151.                 ;MsgBox, Error
  152.                 if(endTable == 1){
  153.                     textVar4=
  154.                     (
  155.                     </tbody>
  156.                     </table>
  157.                     )
  158.                     SetWorkingDir %A_ScriptDir%
  159.                     FileAppend, %textVar4%`n, ReadErrors.html
  160.                     SetWorkingDir %A_ScriptDir%/pcxLogs
  161.                     endTable:=0
  162.                 }
  163.                 break
  164.             }
  165.                
  166.             if (InStr(line, "<tr><td><a href=""/station/statistic/", true, 1) > 0){
  167.                 scannerNamePos := InStr(line, "/station/statistic/", true, 1)
  168.                 scannerNamePos := scannerNamePos + 19
  169.                 i := 1
  170.                 Loop{
  171.                     if(SubStr(line, scannerNamePos + i, 1) != Chr(46)){
  172.                         i++
  173.                     }
  174.                     else{
  175.                         break
  176.                     }
  177.                 }
  178.                 scannerName := SubStr(line, scannerNamePos, i)
  179.                
  180.                 filePos := InStr(line, "</a></td><td>", false, 0)
  181.                 filePos := filePos + 13
  182.                
  183.                 i := 1
  184.                 Loop{
  185.                     if(SubStr(line, filePos + i, 1) != Chr(60)){
  186.                         i++
  187.                     }
  188.                     else{
  189.                         break
  190.                     }
  191.                 }
  192.                 totalScan := SubStr(line, filePos, i)
  193.                 ;MsgBox, %totalScan%
  194.                
  195.                 filePos := filePos + 9 + i
  196.                 i := 1
  197.                 Loop{
  198.                     if(SubStr(line, filePos + i, 1) != Chr(60)){
  199.                         i++
  200.                     }
  201.                     else{
  202.                         break
  203.                     }
  204.                 }
  205.                 readErr := SubStr(line, filePos, i)
  206.                 ;MsgBox, %readErr%
  207.                
  208.                 readErrPercent := Round(((readErr/totalScan)*100), 2)
  209.                
  210.                 UrlDownloadToFile, %addressName%/station/statistic/%scannerName%.html, LastHourScanner_%fileName%.txt
  211.                 LastHrLine := 160
  212.                 readErrLastHrReadTotal := 0
  213.                 readErrLastHrErrTotal := 0
  214.                 Loop, {
  215.                     FileReadLine, line2, LastHourScanner_%fileName%.txt, %LastHrLine%
  216.                     if(ErrorLevel != 0){
  217.                         break
  218.                     }
  219.                     if(InStr(line2, "<b>Time</b>", true, 1) > 0){
  220.                         ;MsgBox, Time Found
  221.                         LastHrLine += 5
  222.                         Loop, {
  223.                             FileReadLine, line2, LastHourScanner_%fileName%.txt, %LastHrLine%
  224.                             if(Instr(line2, "</p>", false, 1) = 0){
  225.                                 LastHrLine += 1
  226.                             }
  227.                             else{
  228.                                 break
  229.                             }
  230.                         }
  231.                         ;MsgBox, Found1
  232.                         iT := 1
  233.                         Loop, {
  234.                             if(iT = 3){
  235.                                 LastHrLine += 100
  236.                                 break
  237.                             }
  238.                             LastHrLine -= 1
  239.                             FileReadLine, line2, LastHourScanner_%fileName%.txt, %LastHrLine%
  240.                             subPos := Instr(line2, "</td><td>", true, 1)
  241.                             subPos += 9
  242.                             iL := 1
  243.                             Loop, {
  244.                                 if(SubStr(line2, subPos + iL, 1) != Chr(60)){
  245.                                     iL++
  246.                                 }
  247.                                 else{
  248.                                     break
  249.                                 }
  250.                             }
  251.                             temp := SubStr(line2, subPos, iL)
  252.                             ;MsgBox, %temp%
  253.                             readErrLastHrReadTotal += temp
  254.                             subPos := InStr(line2, "</td><td>", true, 1, 2)
  255.                             subPos += 9
  256.                             iL := 1
  257.                             Loop, {
  258.                                 if(SubStr(line2, subPos + iL, 1) != Chr(60)){
  259.                                     iL++
  260.                                 }
  261.                                 else{
  262.                                     break
  263.                                 }  
  264.                             }
  265.                             temp := SubStr(line2, subPos, iL)
  266.                             ;MsgBox, %temp%
  267.                             readErrLastHrErrTotal += temp
  268.                             iT += 1
  269.                         }
  270.                     }
  271.                     LastHrLine += 1
  272.                 }
  273.                 ;MsgBox, %readErrLastHrReadTotal%`n%readErrLastHrErrTotal%
  274.                 LastHourPercent := readErrLastHrErrTotal/readErrLastHrReadTotal*100
  275.                 LastHourPercent := Round(LastHourPercent,2)
  276.                    
  277.                 if(readErrPercent > readPerc or LastHourPercent > readPerc){
  278.                     SetWorkingDir %A_ScriptDir%
  279.                     if(pcxHeader == 0){
  280.                         textVar2=
  281.                         (
  282.                         <h2><a title='PCX %pcxNum% Scanners' href='%addressName%/station/index.html' target="_blank">
  283.                         <span class="tg"><em class="tg-xyod"> <strong> PCX %pcxNum%</strong></em></span></a></h2>
  284.                         <table class="tg">
  285.                         <tbody>
  286.                             <tr>
  287.                                 <td class="tg-xyoc">Scanner Name</td>
  288.                                 <td class="tg-xyoc">Read Errors</td>
  289.                                 <td class="tg-xyoc">Read Error `%</td>
  290.                                 <td class="tg-xyoc">Read Errors in Last Hour</td>
  291.                                 <td class="tg-xyoc">Read Error `% in Last Hour</td>
  292.                             </tr>
  293.                         )
  294.                         FileAppend, %textVar2%`n, ReadErrors.html
  295.                         pcxHeader=1
  296.                         endTable=1
  297.                     }
  298.                     ;MsgBox, %addressName%/station/statistic/%scannerName%.html
  299.                     textVar3=
  300.                     (
  301.                         <tr>
  302.                             <td class="tg-vqva"><span style="color:#3166FF">%scannerName%</span></td>
  303.                             <td class="tg-vqva">%readErr%</td>
  304.                             <td class="tg-dibh"><span style="color:#FE0000">%readErrPercent%</span></td>
  305.                             <td class="tg-vqva">%readErrLastHrErrTotal%</td>
  306.                             <td class="tg-dibh">%LastHourPercent%</td>
  307.                         </tr>
  308.                     )
  309.                     FileAppend, %textVar3%`n, ReadErrors.html
  310.                     SetWorkingDir %A_ScriptDir%/pcxLogs
  311.                 }
  312.             }
  313.             pcxFileLine := pcxFileLine + 1
  314.         }
  315.         pInd += (100/MaxVal)
  316.         Progress, %pInd%
  317.     }
  318.  
  319.     Progress, Off
  320.  
  321.     Sleep, 500
  322.     SetWorkingDir %A_ScriptDir%
  323.     If WinExist("ReadErrors.html"){
  324.         WinActivate, ReadErrors.html
  325.         Sleep, 300
  326.         Send {F5}
  327.     }
  328.     else{
  329.         Run, ReadErrors.html
  330.     }
  331.     Run, copyToLog.bat
  332.  
  333.     Exit()
  334. }
  335.  
  336. ReadConfig()
  337. ConnectionTest()
  338.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement