This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Getting first Line of a on-the-web-located file

Help for those learning Tcl or writing their own scripts.
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

Getting first Line of a on-the-web-located file

Post by aap »

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
User avatar
SaPrOuZy
Halfop
Posts: 75
Joined: Wed Mar 24, 2004 7:38 am
Location: Lebanon

Post by SaPrOuZy »

try using egghttp.tcl
or search the forum for http package
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

Post by aap »

I found this:

Code: Select all

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?
User avatar
SaPrOuZy
Halfop
Posts: 75
Joined: Wed Mar 24, 2004 7:38 am
Location: Lebanon

Post by SaPrOuZy »

try to replace:
foreach e [split [::http::data $x] \n] {
regsub -all {<([^<])*>} $e {} e
puthelp "privmsg $c :$e"
}
with
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]
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

Post by aap »

:) It worked...

Thanks a lot!
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

wrong number of args

Post by aap »

I really hate this...

I have now:

Code: Select all

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? :)
d
deadite66
Halfop
Posts: 74
Joined: Mon May 30, 2005 2:49 am
Location: Great Yarmouth, UK

Post by deadite66 »

if you want the procedure called when someone issue a command in the channel change utimer to

Code: Select all

bind pub - !line now
<- tcl newb
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

Post by aap »

I really need a timer, since the channel is not that crowded ;)
other idea's to solve it?
d
deadite66
Halfop
Posts: 74
Joined: Mon May 30, 2005 2:49 am
Location: Great Yarmouth, UK

Post by deadite66 »

Code: Select all

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
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

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: Select all

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)
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

Post by aap »

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.
d
deadite66
Halfop
Posts: 74
Joined: Mon May 30, 2005 2:49 am
Location: Great Yarmouth, UK

Post by deadite66 »

won't that utimer just run the proc once when the bot starts up?
<- tcl newb
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

Post by aap »

so far I know

utimer is the same as timer, but in seconds
a
aap
Voice
Posts: 13
Joined: Sun Jun 18, 2006 8:21 pm

Post by aap »

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: Select all

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"
   }
}
d
deadite66
Halfop
Posts: 74
Joined: Mon May 30, 2005 2:49 am
Location: Great Yarmouth, UK

Post by deadite66 »

that will only work on a local file not from the internet

try this

Code: Select all

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
Post Reply