Sign in to follow this  
Followers 0
Faleira

check?

5 posts in this topic

Hey, i'm working on a logging system of mine but i've hit a problem...

here's the code:

#Include <Array.au3>
#Include <File.au3>

Local Const $LOG_PATH = @ScriptDir & '\log.lsz'

; Read HTML data into variables
Local $HTMLBodyData = FileRead('html.body', FileGetSize('html.body'))

; Find the location of the first <FONT> tag after the first
; <SPAN id=s_Chat> tag and trim all data before it
Local $LogData = StringMid($HTMLBodyData, StringInStr($HTMLBodyData, '<SPAN id=s_Chat>&nbsp;'))
$LogData = StringMid($LogData, StringInStr($LogData, '<FONT'))

; Find the first <BR> tag and remove it and all trailing data
$LogData = StringLeft($LogData, StringInStr($LogData, '<BR>'))

; Check that $LogData contains the desired information
MsgBox(0x40, '$LogData', $LogData)

;pm
$pmexist = StringInStr($LogData, "javascript:pm")
If $pmexist <> 0 Then
    $startname = StringInStr($LogData, ">")
    $name = StringMid($LogData, $startname, StringLen($LogData))
    $name = StringMid($name, StringInStr($name, "<a href"), StringLen($name))
    $endname = StringInStr($name, "')"">")
    $name = StringMid($name, 1, $endname + 3)
    $LogData = StringReplace($LogData, $name, "<font color = ""C89468"">")
    $LogData = StringReplace($LogData, "</a>", "</font>")
EndIf
;/pm

; Append the information to the log
_FileWriteLog($LOG_PATH, $LogData & 'BR>')

; Load all log details in reverse-chronological order
Local $LogArray
_FileReadToArray($LOG_PATH, $LogArray)
_ArrayReverse($LogArray, 1)

; Open log for overwriting
$LogHandle = Fileopen(@ScriptDir & "\logs\Log.html", 2)

; Write out the HTML header
FileWrite($LogHandle, FileRead("html.head", FileGetSize("html.head")))

; Can't use _FileWriteFromArray() because it will overwrite the header
; No big deal
FileWrite($LogHandle, $LogArray[0])
Local $I
For $I = 1 To UBound($LogArray) - 1
    FileWrite($LogHandle, @CRLF & $LogArray[$I])
Next

; Write out the HTML footer
FileWrite($LogHandle, FileRead("html.tail", FileGetSize("html.tail")))

; Close the file
FileClose($LogHandle)

The thing is that i want to use that withing a While loop so that it keeps repeating over n over to keep logging everything new that comes out. But it just keeps logging the same messages over and over. At first, i thought i could probably load them into another variable and check, but then i realise if the same message comes twice, it won't log the second one... anyway for me to fix this?


[quote]If whenever you feel small, useless, offended, depressed, and just generally upset always remember......you were once the fastest and most vicious sperm out of hundreds of millions![/quote]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

not sure if this is what your asking for.

#Include <Array.au3>
#Include <File.au3>
HotKeySet("{Esc}", "_Terminate")
Local Const $LOG_PATH = @ScriptDir & '\log.lsz'

While 1
; Read HTML data into variables
    Local $HTMLBodyData = FileRead('html.body', FileGetSize('html.body'))
    
; Find the location of the first <FONT> tag after the first
; <SPAN id=s_Chat> tag and trim all data before it
    Local $LogData = StringMid($HTMLBodyData, StringInStr($HTMLBodyData, '<SPAN id=s_Chat>&nbsp;'))
    $LogData = StringMid($LogData, StringInStr($LogData, '<FONT'))
    
; Find the first <BR> tag and remove it and all trailing data
    $LogData = StringLeft($LogData, StringInStr($LogData, '<BR>'))
    
; Check that $LogData contains the desired information
    MsgBox(0x40, '$LogData', $LogData)
    
;pm
    $pmexist = StringInStr($LogData, "javascript:pm")
    If $pmexist <> 0 Then
        $startname = StringInStr($LogData, ">")
        $name = StringMid($LogData, $startname, StringLen($LogData))
        $name = StringMid($name, StringInStr($name, "<a href"), StringLen($name))
        $endname = StringInStr($name, "')"">")
        $name = StringMid($name, 1, $endname + 3)
        $LogData = StringReplace($LogData, $name, "<font color = ""C89468"">")
        $LogData = StringReplace($LogData, "</a>", "</font>")
    EndIf
;/pm
    
; Append the information to the log
    _FileWriteLog($LOG_PATH, $LogData & 'BR>')
    
; Load all log details in reverse-chronological order
    Local $LogArray
    _FileReadToArray($LOG_PATH, $LogArray)
    _ArrayReverse($LogArray, 1)
    
; Open log for overwriting
    $LogHandle = FileOpen(@ScriptDir & "\logs\Log.html", 2)
    
; Write out the HTML header
    FileWrite($LogHandle, FileRead("html.head", FileGetSize("html.head")))
    
; Can't use _FileWriteFromArray() because it will overwrite the header
; No big deal
    FileWrite($LogHandle, $LogArray[0])
    Local $I
    For $I = 1 To UBound($LogArray) - 1
        FileWrite($LogHandle, @CRLF & $LogArray[$I])
    Next
    
; Write out the HTML footer
    FileWrite($LogHandle, FileRead("html.tail", FileGetSize("html.tail")))
    
; Close the file
    FileClose($LogHandle)
WEnd

Func _Terminate()
    Exit
EndFunc  ;==>_Terminate
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

well, that's just nesting it in the while, but what i mean is

say, i'm logging a chat window that looks like this:

1> Hi

2>Hello

1>blah blah

So, normally, as i run the script, it would write the first line into the html file. But as the script is right now, when i nest it in a loop, it'll nonstop write the same line, and the html file would be logged like...

1> Hi

1> Hi

1> Hi

1> Hi

1> Hi

1> Hi

1> Hi

Until that first line is changed and pushed down by a new post. What i want to do, is have it so that it doesnt' write the line to the html file unless it's a different post. Originally, i figured i could just make it store the first line into a variable, and have it just see if the string is equal the the variable, and if it was, then don't write. But then, i realsied i would hit a problem if the same thing were to ever be posted twice.

For example, if i did that, and i wanted to log something like

1>2

1>3

1>4

1>2

1>2

1>3

It wouldn't work, for the "1>2"s that follow each other, and only one would get logged. I then figured i could probably add another variable to check the second one, but then that becomes kind of annoying to check like that. As well, it all screws up if i stop the script and run it again, since the info within the variable would be gone.

[quote]If whenever you feel small, useless, offended, depressed, and just generally upset always remember......you were once the fastest and most vicious sperm out of hundreds of millions![/quote]

Share this post


Link to post
Share on other sites

More context would help. What are you really trying to do? Where do the files you are working with comming from?

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

If the chat output takes place in a control that can read via ControlGetText() and the text continually builds up (i.e. old messages are never discarded) then you could determine the length of text in the control, watch for changes to that length and then read the new text by comparing the lengths.

Share this post


Link to post
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
Sign in to follow this  
Followers 0