| View previous topic :: View next topic |
| Author |
Message |
whittinghamj Op
Joined: 21 May 2006 Posts: 103
|
Posted: Thu May 25, 2006 10:35 pm Post subject: read txt file |
|
|
Good evening yall.
I have been reading the forum's and not getting very fare. Its been one of those days. I know its on the board somewhere but I cannot find it.
I have a file which contains a user's nick and then a timestamp. We use it to keep track of when users where first seen on our channel.
The question I have is this. I want to be able to type !users and eggie goes off and lists every line in the text file eg
<User>!users
<bot>nick1 2006 05 05
<bot> nick2 2005 05 01
etc.
It does not need to re-order the lines or anything just read them out as they are shown in the txt file.
Here is an example of exactly how the text file looks.
| Code: | Quest 2006 05 21 19 27
Wolfie 2006 05 23 19 34
Ladybug 2006 05 23 19 38
NeXXtea 2006 05 23 19 39 |
Any help would be extremly helpful.
Kind Regards and god bless |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Thu May 25, 2006 10:43 pm Post subject: |
|
|
Step one, have Wolfie smack you for not asking me first.
Step two, look here |
|
| Back to top |
|
 |
whittinghamj Op
Joined: 21 May 2006 Posts: 103
|
Posted: Thu May 25, 2006 10:50 pm Post subject: |
|
|
no [censored] - lmfao hey man
hows it going fancy seeing you here.
cheers buddy. |
|
| Back to top |
|
 |
whittinghamj Op
Joined: 21 May 2006 Posts: 103
|
Posted: Thu May 25, 2006 10:51 pm Post subject: |
|
|
drag - that just reads one file tho buddy. I need it to read / list all the lines  |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Fri May 26, 2006 12:09 am Post subject: |
|
|
| Code: | set fileread "filetest"
bind pub - !users file:read
proc file:read {n u h c t} {
set fl [open $::fileread]
set data [read $fl]
close $fl
set lines [split $data \n]
foreach x $lines {
putserv "privmsg $c $x"
}
}
|
|
|
| Back to top |
|
 |
whittinghamj Op
Joined: 21 May 2006 Posts: 103
|
Posted: Fri May 26, 2006 12:53 am Post subject: |
|
|
thanks buddy - you star you
god bless |
|
| Back to top |
|
 |
pstruh Voice
Joined: 04 Mar 2005 Posts: 11
|
Posted: Tue Jun 06, 2006 3:58 pm Post subject: |
|
|
| DragnLord wrote: | | Code: | set fileread "filetest"
bind pub - !users file:read
proc file:read {n u h c t} {
set fl [open $::fileread]
set data [read $fl]
close $fl
set lines [split $data \n]
foreach x $lines {
putserv "privmsg $c $x"
}
}
|
|
Cau you help me how to read file with delay? I want to read file faster. |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Tue Jun 06, 2006 7:29 pm Post subject: |
|
|
what now? delay or faster?
using
| Code: | while {![eof $fl]} {
lappend lines [gets $fi]
}
close $fl |
would decrease memory usuage and therefore might speed up a little on really large files... but... no idea what could be faster, else you want to use some floody speed and use putquick or even putdccraw ^-^. _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
pstruh Voice
Joined: 04 Mar 2005 Posts: 11
|
Posted: Wed Jun 07, 2006 3:35 am Post subject: |
|
|
I modify the code like that:
| Code: |
proc file:read {n u h c t} {
set fl [open $::fileread]
set data [read $fl]
set lines [split $data \n]
while {![eof $fl]} {
lappend lines [gets $fi]
}
close $fl
foreach x $lines {
putquick "privmsg $c $x"
}
}
|
but I cant see any different of speed reading file beetwen previous code and this code.
Is possible an error in script ....?? |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Wed Jun 07, 2006 3:56 am Post subject: |
|
|
this is because the code does the same as DragnLord's code... you of course need to replace the previous reading and splitting with the new one .
| Code: | proc file:read {n u h c t} {
set fl [open $::fileread]
set lines [split [read $fl] \n]
close $fl
...
} | But as said... due the lag from IRC you will most likely not notice anything. On small files (less than 1mb?) it is be even ~1ms slower (about half the time per iteration with time), since it has more function calls ^-^.
As mentioned... I dont know what kind of speed you except. Bots usual respond time is 1-2sec. You have to edit your source or use putdccraw to skip all queues which will get you flood kicked for sure, unless you have IRCOp control of the server the bot is connected to.
In case your bot really needs a few seconds to read the file, it must be your shells fault, since on shells I know it reads like a few lines within a few ms. So anything smal enough to be redirected to IRC should be read with both functions within a time you cannot notice as a human.
Edit: I noticed I could put together the befits of both . Less function calls and less memory copies . _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
Sir_Cedric_Lex2 Voice
Joined: 03 Jul 2006 Posts: 3
|
Posted: Mon Jul 03, 2006 9:19 am Post subject: |
|
|
I have a problem with a similar tcl...
the programm reads the file, but if thers a "space" character the rest of the line ist missing
for example:
(Google) !google, !g, !search
draws only
(Google)
and the rest (!google, !g, !search) of the line is missing...
please help
greetz
Sir Cedric Lex |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Wed Jul 05, 2006 1:24 am Post subject: |
|
|
posting your script might work?  |
|
| Back to top |
|
 |
|