Sign in to follow this  
Followers 0
Zeerti

Setting up a Queuing System

53 posts in this topic

I am writing a script that reads text from a chat room, recognizes a specific thing from what is said and then runs. I have that functioning, but the problem right now is that it is only doing the one that it sees first and then forgets about any other requests that may have come through while it was running the script. 

What I would like for it to do is set up a que, what I assume would be done via an array push of some sort, so that it does the requests in the order received. I've tried a couple of different methods without any success so If I can get some assistance on this that would be great! I have included the code below.

#include <FileSource.au3>
#include <array.au3>
#include <IE.au3>
#include <File.au3>


;Run("C:\Program Files (x86)\Pidgin\pidgin.exe") ;Start Pidgin
$healthMessage = "===Health Check Results==="
$link = "WEBSITE FOR GSLU"
$oIE = _IECreate($link, Default, 1)
;_IENavigate($oIE, $link, 1)
WinMove("[CLASS:IEFrame]", "", 0, 0, 1050, 656)

;Array of files in log folder
$FileList = _FileListtoArrayEx('C:\Users\Zoidberg\AppData\Roaming\.purple\logs\jabber\sdcim.com.chat', '*.*', 1)
$File = $FileList[$FileList[0]]
;ConsoleWrite($FileList[$FileList[0]])

While True
;Opens the file, reads the last line
$FileHandle = FileOpen($File)
$LineRead = FileReadLine($FileHandle, -1)
FileClose($FileHandle)
;Check if GSLU was found
$RegExArray = StringRegExp($LineRead, ".*?((?i)GSLU).*?(\d+).*?((?i)Health)", 3)
;Start Main Loop
   if Ubound($RegExArray) == 3 Then
      ControlSend( "[CLASS:gdkWindowToplevel]", "", "gdkWindowChild4", "Processing GSLU, ETA 30 seconds." & "{ENTER}")
     ControlSend( "[CLASS:gdkWindowToplevel]", "", "gdkWindowChild4", "{ENTER}" & "{ENTER}" & "{ENTER}")
      WinActive("[CLASS:IEFrame]")
      ClipPut($RegExArray[1]) 
      _IEImgClick($oIE, "SearchIconT.gif")
      sleep(5000)
      MouseClick("left", 465, 220, 1, 0);Search Click
      ;Sleep(100)
      Send(ClipGet())
      Send("{ENTER}")
      Sleep(8000)
      _IELinkClickByText($oIE, "HSI", 0, 1)
      _IELinkClickByText($oIE, "Health Check", 1, 1)
      Sleep(1500)
      MouseClick("Left", 180, 230, 1, 0) ;Clicking Modem
      ;Sleep(100)
      MouseClickDrag("Left", 180, 230, 180, 260, 1) ;Clicking Modem
      MouseClick("Left", 530,280,1,0) ;Clicking Health
      MouseClick("Left", 530,300,1,0) ;Clicking Health
      Sleep(5000)
      MouseClick("Left", 826, 283,1,0) ;Clicking Text Format
      MouseClick("Left", 826, 293,1,0) ;Clicking Text Format
      MouseClick("Left", 500, 260,1,0) ;Clicking Text Format for copying
      Send("^a")
      Send("^c")
      Send("^c")
      ;Sleep(500)
      ;Refining GSLU down to needed info       
      $Final_Text = StringRegExp(ClipGet(), "(CM[^\v]+|Current CMTS Status[^\v]+|Modem Boot File[^\v]+)", 3)
      ControlSend( "[CLASS:gdkWindowToplevel]", "", "gdkWindowChild4", "===Health Check Results===" & @LF & $Final_Text[0] & @LF & $Final_Text[1] & @LF & $Final_Text[2])
      ControlSend( "[CLASS:gdkWindowToplevel]", "", "gdkWindowChild4", "{ENTER}")
      Send("{F5}")
      Sleep(5000)
   
EndIf
Sleep(100)
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

in this special case i would run two scripts.

one script (the child script) parses the chat for keywords and lists them like a que in an ini file (IniWrite).

the second script (the parent script) checks the same ini file list for entries (IniRead), makes the work it should, and then deletes the ini entry (IniDelete)

the second (parent) script start the first (child) one with the Run command and waits until something is written into the ini file.

if the parent script closes, it close the child process as well.

cheers E.

 

Edit: if you have the two scripts ready, i can show you how to merge them again to one script :)

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Is there a way for me to make it so I can compile both scripts into a single file?

 

also thanks a million, I didn't even think about using an ini file.

Edited by Zeerti

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Is there a way for me to make it so I can compile both scripts into a single file?

 

also thanks a million, I didn't even think about using an ini file.

.

my edit came too late:

Edit: if you have the two scripts ready, i can show you how to merge them again to one script :)

 .

so, yes, can be compiled as one

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

excuse me Edano,

do not arise problems if 2 programs try to access in read and write mode to the same ini file at the same time?


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

excuse me Edano,

do not arise problems if 2 programs try to access in read and write mode to the same ini file at the same time?

 

Actually this isn't an issue assuming they aren't both writing. My current script is reading a chat log that is continually being updated by the chat client and I've had no issues with is so far! :)

so, yes, can be compiled as one

 

Alright, well I shall write it up and get back to you on how to do this! I assume it is possible for the .ini file to be saved within as well?

Edited by Zeerti

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

no, just make a loop until no error is returned in both scripts. iniwrite read has the advantage that the file is only opened a very short time (some ms).

you have to check the read write commands for errors and loop until @error=0

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Alright, well I shall write it up and get back to you on how to do this! I assume it is possible for the .ini file to be saved within as well?

.

first part yes, i would love to show you that trick.

second part: no, the inifile is only extern, but you can hide it in the temp directory if you want.

btw.: the child script can work invisibly, without gui and taskbar icon.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

no, just make a loop until no error is returned in both scripts. iniwrite read has the advantage that the file is only opened a very short time (some ms).

you have to check the read write commands for errors and loop until @error=0

 

I haven't messed around with it yet, but I don't understand what you are getting at with looping until the error returns 0. Why would it not return 0?

Share this post


Link to post
Share on other sites

That's assuming that Ini* functions use file locks, which might not be the case.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I haven't messed around with it yet, but I don't understand what you are getting at with looping until the error returns 0. Why would it not return 0?

.

that was an answer to pincopanco's remark, not to you :)

I haven't messed around with it yet, but I don't understand what you are getting at with looping until the error returns 0. Why would it not return 0?

.

do

$x=iniwrite(.....)

until $x>0 (0 would mean the file is locked) 

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

That's assuming that Ini* functions use file locks, which might not be the case.

 

I know that the FileOpen() doesn't lock it, I just assumed the ini read/write would be the same. I didn't even consider it locking it an option.

 

do

$x=iniwrite(.....)

until $x>0 (0 would mean the file is blocked) 

 

So essentially looping it tell it sees the error that it's blocked and then it stops and then will resume when the return value is 1 for instance. Right?

Edited by Zeerti

Share this post


Link to post
Share on other sites

just in case :)

1 person likes this

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

no, just make a loop until no error is returned in both scripts. iniwrite read has the advantage that the file is only opened a very short time (some ms).

you have to check the read write commands for errors and loop until @error=0

 

.... well, it's a trick  :)

do you know if SQLite can manage concurrent  r/w accesses ?


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Then this approach is likely to fail. In fact and since it has a non-zero probability of failure, it WILL fail, and at the worst moment, of course, provided it's used long enough for the "disaster" (*) to occur.

(*) read: unexpected failure

To the last post: YES, SQLite will hapily do the job with no chance of failure.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

so many crossing posts .... yes it can be done and will work nicely (towards the OP's question)


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Edano,

What makes you believe that Ini* functions use any kind of isolation?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

ok i make two example scripts and try it out ..... okay ?

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

:whistle: ...... I would recommend this small reading..... :)

2 people like this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

ok i make two example scripts and try it out ..... okay ?

 

Let me know what happens!

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