Jump to content

Automating Printer Toner Levels


Recommended Posts

this code works for me:

[autoit]c2--><!--CiNpbmNsdWRlICZsdDtBcnJheS5hdTMmZ3Q7CiNpbmNsdWRlICZsdDØUÞQS^VÒÒLVLVÕYÒ^ÌÖ]VV^YÝÛÚUÍZÖÐ[XMÔECeeU$tÆÔcצæDG4´ó$VvVÕgV$vÇ%¥4'E¥&ö#%v#%u£%cDvÇU§&w35v ¥v4)Á¹I±¥ Íiai±!5-Qå©e]Ý)¥5Ý5édÝU!)Á¹I±¹95°ÁAM 5MݵaYÙѽ!IÝ=¤áÙ5kyLjE2OC4xLjEwMS9pbm

leC5odG1sJnF1b3Q7XQpGb3IgJiMwMzY7cCA9IDEgdG8gJiMwMzY7UÛQÐÕ^LÒPÖZQLÌÛ[NLÒQÝÙÒS]Ó^MÖ[XÌÔXÍÔ46vÄÖ#$æ$4Ô¤¤æ§EF$sw¦FEw¤æD6vÄÖ#$æ$4Ô¤¤æ§FDvÇU¥Ô´55¤ÔDÓ £§µIa)é9Íea9é%Á)¹ÅÍDÝdÉá¡Í4å! ÈÕéÅ¡eµá±EµáÙdÉÑ%i]­ia)Uia Á)µÁyZxdW90OyAKCSYjMDM2O

ZpbmRGaXJzdFBlcmNlbnQgPSAmcXVvdDtDYXJ0cmlkZ2UmYW1wO25iÌÐMÒQÑV[ÓÞVÎLÝÛÒS]Ó^MØÌLXÛSQÖÖÕVL[ÒS]Ó^MT§&å&Æ6äæ$¦×t×¥v4c6vÄ¥¦$¥§#4udvÆ&$F##SsS¥Wf#4´55¤ÔDФó$dÕ±åå%8Áµ±ÕhÅ9Ý°Á-

e©54É<Í9Ùa)©iMáDÅ)5I¥Ýá-E½))¥5Ý5édݹYÑ%Á5½Q29uc29sZVdyaXRlKCYj

DM2O3NvdXJjZSZhbXA7QExGKQoJRm9yICYjMDM2O2kgPSAxIHRvICYQLÌXUÍ[ÌÝÖ[ÒÔÖZQLÌÓØUÍ[QÒS]ÓBMÖU^UÞVZQLÌÙÚÒÕÖuS5'sVå5sUFDô¦×t×¥v3'&ÕW45¤ÔDÓ$ó§&Õ$v§¦DTç5礵4%VugT6p¤¤5TÙ

Link to comment
Share on other sites

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

This code:

#include <Array.au3>
#include <File.au3>
#include <INet.au3ÝÂÚ[ÛYH   Ñ^Ù[ÓÓWÕQ]LÉÝÂØH[ZÙHY]ÙÙÙ][ÈHÝb&çFW"ÆWfVÇ0¤Æö6Âb33cµ&çFW'5³UÒÒ³BÂgV÷C¶GG¢òó"ãcããöæ๡ѵ°ÅÕ½Ðì°ÅÕ½Ðí¡ÑÑÀè¼¼ÄäȸÄØà¸Ä¸ÄÀĽ¥¹à¹¡Ñµ°ÅÕ½Ðì°ÅÕ½Ðí¡ÑÑÀè¼¼Ääȸ68.1.101/index.html","http://192.168.1.101/index.html"]
For ÌÍÜHHÈ  ÌÍÔ[ÖÌBSØØ[  ÌÍÙÝÝÈH
    ÌÍÙÝÛÛ[âÒ@ Æö6Âb33cµ6Æ÷E³uÕ³5Ð Æö6Âb33c¶ÆæW0 b33c´fæDf'7D6Æ72ÒgÕ½Ðí±ÍÌõ¡Á
½¹ÍÕµ±    ±½­!ÉQáÐÐìÅÕ½Ðì($ÀÌØí¥¹¥ÉÍÑAɹÐôquot;Cartridge&nbsp;&nbsp;"
    $source = _INetGetSource(&#0ÍÔ[ÖÉÌÍÜJBRYÜ[ÛÛ[YSÛÜIÌÍØS[ÈHÝ[ÔÜBb33c·6÷W&6RÄ5$Äbà b33c¶çVÒÒ 6öç6öÆUw&FRb33c·6÷W&6Rf×´Äb%½ÈÀÌØí¤ôÄѼÀÌØí1¥¹ÍlÁt($$ÀÌØíͱ¥¹ôÀÌØí1¥¹ÍlÀÌØí¥t($If StringInStr($sline, $FindFirstClass) Then
            ConsoleWrite(&#03ÚI[ÐBBBIÌÍÔÛÝHÝ[Õ[SY
    ÌÍÜÛ[[Ó[    ÌÍÑ[Df'7D6Æ72 b33cµW&6VçBÒ7G&æuG&ÔÆVgBb33c¶ÆæW5²b33c¶³ÒÅ7G&¹1¸ ÀÌØí¥¹¥ÉÍÑAɹФ¤($$$ÀÌØíAɹÑA½ÌôMÑÉ¥¹%¹MÑÈ ÀÌØíAÉnt,"%")
            $Percent = StringLeft($Percent,$PercentÜÈHJBBBIÌÍÔÛÝÌVÌHH  ÌÍÔÛÝÌVÌH
ÈBBBIÌÍÔÛÝÉÌÍÔÛݳճÕÕ³ÓÒb33cµ6Æ÷E@ b33cµ6Æ÷E²b33cµ6Æ÷E³Õ³ÕÕ³%ÓÒb33cµW&6Vç@ $ÀÌØí¤¬ôÄ($%¹%(%9áÐ($(%1½°ÀÌØí½á°ô}á± ½½­=Á¸ ÅÕ½Ðíè92;Printers.xls",0)
    For $i = 1 to $Slot[0][0]
        _ExcelWriteÙ[
    ÌÍÛÑ^Ù[    ÌÍÔÛÝÉÌÍÚWVÌK ÌÍÙÝÝÊÉÌÍÜLK  ÌÍÙ'7D6öÇVÖâ²b33c¶Ó 6öç6öÆUw&FRb33cµ6Æ÷E²b33c¶Õ³ÒfײgV÷C³¢gV÷ì¤($%
½¹Í½±]É¥Ñ ÀÌØíM±½ÑlÀÌØí¥ulÉtµÀí1¤(%9áÐ(%}á±    ½½­MÙ À6;oExcel)

    _ExcelBookClose($oExcel)
    $Slot[0][0] = 0
Next

Yields the attached file

I am running Office 2k3, though that shouldnt make the slightest difference. Try my code exactly as it is, changing only the url's and the spreadsheet path, and post the xls if it's still messed up.

Link to comment
Share on other sites

This line

$Percent = StringTrimLeft($aLines[$i+1],StringLen($FindFirstPercent))

and precisely this bit

StringLen($FindFirstPercent)

cut off the &nbsp;, if you change the find string to just Cartridge, it wont cut off enough!

Link to comment
Share on other sites

I made more mods, mostly for clarity:

#include <Array.au3>
#include <File.au3>
#include <INet.au3>
#include <ExcelCOM_UDF.au3>
;a zenlike method of getting a list of printer levels
Local $filePrinterList = "C:\PrinterList.txt"
Local $fileXLS= "C:\Printers.xls"
;
Local $FindFirstClass = "class=hpConsumableBlockHeaderText>" 
Local $FindFirstPercent = "Cartridge&nbsp;&nbsp;"
;
Local $Printers
Local $oExcel = _ExcelBookOpen($fileXLS,0)
If Not _FileReadToArray($filePrinterList,$Printers) Then Exit
For $p = 1 to $Printers[0]
    Local $firstRow = 4, $firstColumn = 4
    Local $Slot[7][3]
    Local $aLines
    
    $source = _INetGetSource($Printers[$p])
    If @error Then ContinueLoop
    $aLines = StringSplit($source,@CRLF,1)
    $num = 0
;ConsoleWrite($source&@LF)
    For $i = 1 to $aLines[0]
        $sline = $aLines[$i]
        If StringInStr($sline, $FindFirstClass) Then
        ;ConsoleWrite($i&@LF)
            $SlotT = StringTrimLeft($sline,StringLen($FindFirstClass))
            $Percent = StringTrimLeft($aLines[$i+1],StringLen($FindFirstPercent))
            $PercentPos = StringInStr($Percent,"%")
            $Percent = StringLeft($Percent,$PercentPos - 1)
            $Slot[0][0] = $Slot[0][0] + 1
            $Slot[$Slot[0][0]][1]= $SlotT
            $Slot[$Slot[0][0]][2]= $Percent
            $i+=1
        EndIf
    Next
    
    
    For $i = 1 to $Slot[0][0]
        _ExcelWriteCell($oExcel, $Slot[$i][2], $firstRow+$p-1, $firstColumn+$i-1)
        ConsoleWrite($Slot[$i][1]&":")
        ConsoleWrite($Slot[$i][2]&@LF)
    Next
    $Slot[0][0] = 0
Next
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel)

Make a file somewhere called whatever you want, and in it, put a list of printer URL's, as such:

http://192.168.1.101/index.html

http://192.168.1.102/index.html

http://192.168.1.103/index.html

http://192.168.1.104/index.html

http://192.168.1.105/index.html

make sure to leave no blanks at the top.

the script will read this in to make it's array of printers. to rearrange the order in the xls, rearrange them in this list

I think it makes it easier, dont you? :rolleyes:

I sped up the execution by not repeating the open and close also.

Link to comment
Share on other sites

The computer world moves fast eh? I just made a new version that skips the text file and instead reads it out of your xls :rolleyes:

#include <Array.au3>
#include <File.au3>
#include <INet.au3>
#include <ExcelCOM_UDF.au3>
;a zenlike method of getting a list of printer levels
Local $fileXLS= "C:\Printers.xls"
;
Local $FindFirstClass = "class=hpConsumableBlockHeaderText>" 
Local $FindFirstPercent = "Cartridge&nbsp;&nbsp;"
;
Local $Printers
Local $oExcel = _ExcelBookOpen($fileXLS,0)
Local $firstRow = 3, $firstColumn = 4
$Printers = _ExcelReadArray($oExcel, $firstRow, $firstColumn-1, 256, 1, 1)
$Printers[0]=_ExcelReadCell($oExcel,$firstRow-1,$firstColumn-1)

For $p = 1 to $Printers[0]
    
    Local $Slot[7][3]
    Local $aLines
    
    $source = _INetGetSource($Printers[$p])
    If @error Then ContinueLoop
    $aLines = StringSplit($source,@CRLF,1)
    $num = 0
;ConsoleWrite($source&@LF)
    For $i = 1 to $aLines[0]
        $sline = $aLines[$i]
        If StringInStr($sline, $FindFirstClass) Then
;ConsoleWrite($i&@LF)
            $SlotT = StringTrimLeft($sline,StringLen($FindFirstClass))
            $Percent = StringTrimLeft($aLines[$i+1],StringLen($FindFirstPercent))
            $PercentPos = StringInStr($Percent,"%")
            $Percent = StringLeft($Percent,$PercentPos - 1)
            $Slot[0][0] = $Slot[0][0] + 1
            $Slot[$Slot[0][0]][1]= $SlotT
            $Slot[$Slot[0][0]][2]= $Percent
            $i+=1
        EndIf
    Next
    
    
    For $i = 1 to $Slot[0][0]
        _ExcelWriteCell($oExcel, $Slot[$i][2], $firstRow+$p-1, $firstColumn+$i-1)
        ConsoleWrite($Slot[$i][1]&":")
        ConsoleWrite($Slot[$i][2]&@LF)
    Next
    $Slot[0][0] = 0
Next
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel)

Column C, the address column, needs to be something like this

Row1: Address

Row2: =COUNTA(C3:C1024)

Row3: http://192.168.1.101/index.html

Row4: http://192.168.1.102/index.html

etc....

very zen.

Edited by Zacharot
Link to comment
Share on other sites

I like the setup much better, but I am still getting

&nbsp;&nbsp;83 &nbsp;&nbsp;54 &nbsp;&nbsp;6 &nbsp;&nbsp;89 &nbsp;65 &nbsp;72

&nbsp;&nbsp;83 &nbsp;&nbsp;54 &nbsp;&nbsp;6 &nbsp;&nbsp;89 &nbsp;65 &nbsp;72

&nbsp;&nbsp;83 &nbsp;&nbsp;54 &nbsp;&nbsp;6 &nbsp;&nbsp;89 &nbsp;65 &nbsp;72

&nbsp;&nbsp;83 &nbsp;&nbsp;54 &nbsp;&nbsp;6 &nbsp;&nbsp;89 &nbsp;65 &nbsp;72

&nbsp;&nbsp;83 &nbsp;&nbsp;54 &nbsp;&nbsp;6 &nbsp;&nbsp;89 &nbsp;65 &nbsp;72

I do not understand what you were trying to tell me a few posts ago about fixing that.

I keep scrolling down to reference stuff and you post again with new stuff !!

Should I go with your new code or try to fix the above first ?

Link to comment
Share on other sites

yes, use the newest, I'll halt my meddling long enough for you to try it :rolleyes:

If need be, I could code in some debug messages and just have you paste them back in here, but after you try this!

Edited by Zacharot
Link to comment
Share on other sites

It did nothing

I just added the info you post for the excel file and modified the location from C:\printers.xls to G:\printers.xls

Ran the script and opened the Printers.xls and nothing in there.

Link to comment
Share on other sites

I got lucky !

I made this change and it works perfect.

By putting in spaces for xx% and adding </SPAN> and 3 more spaces after, it only inputs the xx%

Local $FindFirstPercent = "Cartridge&nbsp;&nbsp; </SPAN> "

Edited by Moscar
Link to comment
Share on other sites

I was indeed adding error messages :rolleyes:

#include <Array.au3>
#include <File.au3>
#include <INet.au3>
#include <ExcelCOM_UDF.au3>
;a zenlike method of getting a list of printer levels
Local $filePrinterList = "C:\PrinterList.txt"
Local $fileXLS= "C:\Printers.xls"
;
Local $FindFirstClass = "class=hpConsumableBlockHeaderText>" 
Local $FindFirstPercent = "Cartridge&nbsp;&nbsp;"
;
Local $Printers
Local $oExcel
$oExcel = _ExcelBookOpen($fileXLS,0)
If Not IsObj($oExcel) Or @error Then 
    ConsoleWrite("Couldnt Call Excel"&@LF)
    Exit
EndIf
Local $firstRow = 3, $firstColumn = 4
$Printers = _ExcelReadArray($oExcel, $firstRow, $firstColumn-1, 256, 1, 1)
If Not IsArray($Printers) Or @error Then
    ConsoleWrite("Couldnt get Printers List from Excel"&@LF)
    Exit
EndIf
$Printers[0]=0
$Printers[0]=_ExcelReadCell($oExcel,$firstRow-1,$firstColumn-1)
If $Printers[0] = 0 Then
    ConsoleWrite("Couldnt get Printer Count, use: =COUNTA(C3:C1024) In C2 To get Count"&@LF)
    Exit
EndIf
For $p = 1 to $Printers[0]
    Local $Slot[7][3]
    Local $aLines
    $source = _INetGetSource($Printers[$p])
    If $source = "" Or $source = " " Or @error Then 
        _ExcelWriteCell($oExcel, "Error", $firstRow+$p-1, $firstColumn)
        ContinueLoop
    EndIf
    $aLines = StringSplit($source,@CRLF,1)
    If $aLines[0] <= 1 Then
        _ExcelWriteCell($oExcel, "Error", $firstRow+$p-1, $firstColumn)
        ContinueLoop
    EndIf
    $num = 0
    For $i = 1 to $aLines[0]
        $sline = $aLines[$i]
        If StringInStr($sline, $FindFirstClass) Then
            ConsoleWrite("----------"&@LF)
            ConsoleWrite("Class Line:: "&$sline&" :: on line "&$i&" with var: "&$FindFirstClass&@LF)
            ConsoleWrite("Cartr Line:: "&$aLines[$i+1]&" :: on line "&$i+1&" with var: "&$FindFirstPercent&@LF)
            $SlotT = StringTrimLeft($sline,StringLen($FindFirstClass))
            ConsoleWrite("Cartridge Type/Color is: "&$SlotT&@LF)
            $Percent = StringTrimLeft($aLines[$i+1],StringLen($FindFirstPercent))
            $PercentPos = StringInStr($Percent,"%")
            $Percent = StringLeft($Percent,$PercentPos - 1)
            ConsoleWrite("Cartridge Percentage is: "&$Percent&@LF)
            $Slot[0][0] = $Slot[0][0] + 1
            $Slot[$Slot[0][0]][1]= $SlotT
            $Slot[$Slot[0][0]][2]= $Percent
            $i+=1
        EndIf
    Next
    For $i = 1 to $Slot[0][0]
        If Not _ExcelWriteCell($oExcel, $Slot[$i][2], $firstRow+$p-1, $firstColumn+$i-1) Or @error Then
            ConsoleWrite("Couldnt Write Data"&@LF)
        EndIf
    Next
    $Slot[0][0] = 0
Next
If Not _ExcelBookSave($oExcel) Or @error Then
    ConsoleWrite("Couldnt Save"&@LF)
EndIf
_ExcelBookClose($oExcel)

lots of error checking mostly, but lots of debug statuses for you.

Edited by Zacharot
Link to comment
Share on other sites

I'm glad it works! I just wish I knew why that works for you, since it makes no sense to me, but hooray for you! :mad:

and for me too! :x:rolleyes::rambo:

are you running the very newest autoit? I hadnt contemplated that you might not be.

Edited by Zacharot
Link to comment
Share on other sites

Well it runs without any error. I guess if it ran into one it would pop up ?

I still get all the &nspb; stuff before the xx% I am running WinXP and Office2003, shouldn't matter like you said.

I does not bother me since I have no clue :rolleyes:

Are you one of the Jon's friends. I was going to donate some money for the hosting bill. It's the least I can do.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...