egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting first Line of a on-the-web-located file
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Sun Jun 18, 2006 8:25 pm    Post subject: Getting first Line of a on-the-web-located file Reply with quote

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
View user's profile Send private message
SaPrOuZy
Halfop


Joined: 24 Mar 2004
Posts: 75
Location: Lebanon

PostPosted: Mon Jun 19, 2006 3:13 am    Post subject: Reply with quote

try using egghttp.tcl
or search the forum for http package
Back to top
View user's profile Send private message
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Mon Jun 19, 2006 6:56 am    Post subject: Reply with quote

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
View user's profile Send private message
SaPrOuZy
Halfop


Joined: 24 Mar 2004
Posts: 75
Location: Lebanon

PostPosted: Mon Jun 19, 2006 7:06 am    Post subject: Reply with quote

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
View user's profile Send private message
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Mon Jun 19, 2006 7:28 am    Post subject: Reply with quote

Smile It worked...

Thanks a lot!
Back to top
View user's profile Send private message
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Mon Jun 19, 2006 7:55 am    Post subject: wrong number of args Reply with quote

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? Smile
Back to top
View user's profile Send private message
deadite66
Halfop


Joined: 30 May 2005
Posts: 74
Location: Great Yarmouth, UK

PostPosted: Mon Jun 19, 2006 10:09 am    Post subject: Reply with quote

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
View user's profile Send private message
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Mon Jun 19, 2006 10:23 am    Post subject: Reply with quote

I really need a timer, since the channel is not that crowded Wink
other idea's to solve it?
Back to top
View user's profile Send private message
deadite66
Halfop


Joined: 30 May 2005
Posts: 74
Location: Great Yarmouth, UK

PostPosted: Mon Jun 19, 2006 10:39 am    Post subject: Reply with quote

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
View user's profile Send private message
krimson
Halfop


Joined: 19 Apr 2006
Posts: 86

PostPosted: Mon Jun 19, 2006 10:42 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Mon Jun 19, 2006 10:48 am    Post subject: Reply with quote

It worked Smile 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
View user's profile Send private message
deadite66
Halfop


Joined: 30 May 2005
Posts: 74
Location: Great Yarmouth, UK

PostPosted: Mon Jun 19, 2006 10:54 am    Post subject: Reply with quote

won't that utimer just run the proc once when the bot starts up?
_________________
<- tcl newb
Back to top
View user's profile Send private message
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Mon Jun 19, 2006 10:55 am    Post subject: Reply with quote

so far I know

utimer is the same as timer, but in seconds
Back to top
View user's profile Send private message
aap
Voice


Joined: 18 Jun 2006
Posts: 13

PostPosted: Mon Jun 19, 2006 11:49 am    Post subject: Reply with quote

New problem Smile

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
View user's profile Send private message
deadite66
Halfop


Joined: 30 May 2005
Posts: 74
Location: Great Yarmouth, UK

PostPosted: Mon Jun 19, 2006 12:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber