| View previous topic :: View next topic |
| Author |
Message |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Sun Jun 18, 2006 8:25 pm Post subject: Getting first Line of a on-the-web-located file |
|
|
Hi,
I want to output the first line of a .txt which is located at http://blablah.com/file.txt
I have the http package (included in TCL right?) But I have no experience in using it.
Its just that I can't find a good example. for each hit on google I get the same page (the page that I don't get with my brains)...
So if someone could give an example, or an URL where I can find a good example would be great.
Thanks,
aap |
|
| Back to top |
|
 |
SaPrOuZy Halfop

Joined: 24 Mar 2004 Posts: 75 Location: Lebanon
|
Posted: Mon Jun 19, 2006 3:13 am Post subject: |
|
|
try using egghttp.tcl
or search the forum for http package |
|
| Back to top |
|
 |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Mon Jun 19, 2006 6:56 am Post subject: |
|
|
I found this:
| Code: | proc foo {n u h c t} {
set x [::http::geturl http://www.domain.com/file.txt]
foreach e [split [::http::data $x] \n] {
regsub -all {<([^<])*>} $e {} e
puthelp "privmsg $c :$e"
}
}
|
And I understand that regsub -all won't read the html tags...
But how can I make the script so it won't read the 2nd line until the end of the file? So it will only output the first line? |
|
| Back to top |
|
 |
SaPrOuZy Halfop

Joined: 24 Mar 2004 Posts: 75 Location: Lebanon
|
Posted: Mon Jun 19, 2006 7:06 am Post subject: |
|
|
try to replace:
| Quote: | foreach e [split [::http::data $x] \n] {
regsub -all {<([^<])*>} $e {} e
puthelp "privmsg $c :$e"
} |
with
| Quote: |
set e [lindex [split [::http::data $x] \n] 1]
regsub -all {<([^<])*>} $e {} e
puthelp "privmsg $c :$e"
} |
i can't test it now, but i think it should work.[/quote] |
|
| Back to top |
|
 |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Mon Jun 19, 2006 7:28 am Post subject: |
|
|
It worked...
Thanks a lot! |
|
| Back to top |
|
 |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Mon Jun 19, 2006 7:55 am Post subject: wrong number of args |
|
|
I really hate this...
I have now:
| Code: |
utimer 15 "now"
proc now {n u h c t} {
set fs [open file.txt r]
gets $fs line(first)
putserv "PRIVMSG $c :$line(first)"
return
} |
eggdrop gives me something like
"wrong # of arguments, should be {now n u h c t}"
and when I do that, it says "should be {now now n u h c t}"
and so on...
Can someone help me?  |
|
| Back to top |
|
 |
deadite66 Halfop
Joined: 30 May 2005 Posts: 74 Location: Great Yarmouth, UK
|
Posted: Mon Jun 19, 2006 10:09 am Post subject: |
|
|
if you want the procedure called when someone issue a command in the channel change utimer to
| Code: | | bind pub - !line now |
_________________ <- tcl newb |
|
| Back to top |
|
 |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Mon Jun 19, 2006 10:23 am Post subject: |
|
|
I really need a timer, since the channel is not that crowded
other idea's to solve it? |
|
| Back to top |
|
 |
deadite66 Halfop
Joined: 30 May 2005 Posts: 74 Location: Great Yarmouth, UK
|
Posted: Mon Jun 19, 2006 10:39 am Post subject: |
|
|
| Code: | bind time - * now ;# runs every minute
proc now {m h d mo y} { |
this will run the procedure every minute, you'll have to change $c on the putserv line to the channel name. _________________ <- tcl newb |
|
| Back to top |
|
 |
krimson Halfop

Joined: 19 Apr 2006 Posts: 86
|
Posted: Mon Jun 19, 2006 10:42 am Post subject: |
|
|
you don't need all those args if you're calling the proc in a timer. the reason why the script doesnt work is that you call the proc with no args, while it requires 'n u h c t' as arguments.
you either give all the params when calling the proc, or you use the following code:
| Code: | set chan "#change_this"
utimer 15 [now $chan]
proc now {chan} {
set fs [open file.txt r]
gets $fs line(first)
putserv "PRIVMSG $chan :$line(first)"
} |
(i don't see why you use 'return' at the end of that proc, so i didn't include it) |
|
| Back to top |
|
 |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Mon Jun 19, 2006 10:48 am Post subject: |
|
|
It worked Thanks,
but just 1 question: How can I change the timer, I mean... change 1 minute to 2 minutes, or 30 seconds. ?
thx
EDIT: that was a reply on the post from deadite66
Last edited by aap on Mon Jun 19, 2006 10:55 am; edited 1 time in total |
|
| Back to top |
|
 |
deadite66 Halfop
Joined: 30 May 2005 Posts: 74 Location: Great Yarmouth, UK
|
Posted: Mon Jun 19, 2006 10:54 am Post subject: |
|
|
won't that utimer just run the proc once when the bot starts up? _________________ <- tcl newb |
|
| Back to top |
|
 |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Mon Jun 19, 2006 10:55 am Post subject: |
|
|
so far I know
utimer is the same as timer, but in seconds |
|
| Back to top |
|
 |
aap Voice
Joined: 18 Jun 2006 Posts: 13
|
Posted: Mon Jun 19, 2006 11:49 am Post subject: |
|
|
New problem
the problem is that 'a' is ALWAYS 0 :S
function of the script:
I want the script to output the first line of a .txt file, ONLY if it is new.
| Code: |
bind time - * man ;# runs every minute
proc man {m h d mo y} {
set a [info exists check]
set fs [open file.txt r]
gets $fs line(first)
close $fs
if { $a == 1 } {
if { $check != $line(first) } {
putserv "PRIVMSG #channel1 :$line(first)"
unset check
set check "$line(first)"
}
} elseif { $a == 0 } {
set burpie "a is 0"
putserv "PRIVMSG #channel1 :$burpie"
set check "$line(first)"
} else {
set burp "damnit, a is not 0 or 1"
putserv "PRIVMSG #channel1 :$burp"
}
} |
|
|
| Back to top |
|
 |
deadite66 Halfop
Joined: 30 May 2005 Posts: 74 Location: Great Yarmouth, UK
|
Posted: Mon Jun 19, 2006 12:39 pm Post subject: |
|
|
that will only work on a local file not from the internet
try this
| Code: | package require http
# set your channel name and url
set channelx "#mychannel"
set fileurl "http://myurl/text.txt"
# don't edit below this line
set ol ""
bind time - * man
proc man {m h d mo y} {
global channelx ol fileurl
set x [::http::geturl $fileurl]
set x2 [split [::http::data $x] \n]
set nl [lindex $x2 0]
if {$nl != $ol} {
set ol [lindex $x2 0]
puthelp "PRIVMSG $channelx :$nl"
}
} |
_________________ <- tcl newb |
|
| Back to top |
|
 |
|