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.

Get a txt file from net and read it

Old posts that have not been replied to for several years.
Locked
x
xiphrex
Voice
Posts: 5
Joined: Fri Apr 29, 2005 8:42 pm

Get a txt file from net and read it

Post by xiphrex »

Hello, first of all I would like to say cheers to the people of this forum as I wouldnt be where I am now without reading the many threads I uncovered in searches.

I have been trying to simply read a text file hosted online, parse it and select data from it and return it in a message to the user who activated the trigger. The code is so far this, and it doesnt get passed the "on to the next proc" log message; and it doesnt give an error either. The text file is also not a .txt but a .ical file, but it can be opened as a txt file. I also took most of the code from this thread: http://forum.egghelp.org/viewtopic.php? ... t=txt+file so cheers to gb for that.

Here is the code

Code: Select all

# Set the chans you want to enable it in to +news
# .chanset #channel +news

# set this to the URL of the news file
set newsfile "http://www.enemydown.co.uk/files/calendar.php?clan=18931"

# want the answer to come out in notice (0) or privmsg (1)?
set tellwho 0

if ![info exists egghttp(version)] {
  putlog "egghttp.tcl was NOT successfully loaded."
  return
}

bind pub - !news getlist

proc getlist {nick uhost hand chan text} {
# if ![channel get $chan news] return
global newsfile
 set sock [egghttp:geturl $newsfile [list processlist $nick]]
  putlog "on to the next proc"
}

proc processlist {nick sock} {
global tellwho
 set todaysdate strftime %Y%m%d
 set data [egghttp:headers $sock]
 foreach line [split $data \n] {
    set start [string first "$todaysmatch" $line]
    set start [expr {$start - 45}] 
    set end [string first "$todaysmatch*STATUS" $line]
    set end [expr {$end - 1}]
    set served [string range $line $start $end]
    putlog "$line"
    putlog "$served"

   if $tellwho {
    putserv "NOTICE $nick :$line"
   } {
    putserv "PRIVMSG $nick :$line"
   }
  }
  if [string match -no Content-Type:* $line] { putlog "Its reached the end bit"}
} 
Can anyone point out where this code is going wrong? Or even better fix it for me? I started reading tutorials for TCL and eggdrop scripting about a week ago, so I am very beginner. Also I have loaded the egghttp.tcl script as I think the code above requires it.

Thanks in advance for any help :D
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

you should get following TCL error:
wrong number of arguments, should "set varName ?value?"
invoked within "set todaysdate strftime %Y%m%d"
at least there are missing the [] braces around the strftime expression.

if you fix this, you will get this one:
no such variable $todaysmatch
invoked within "set start [string first "$todaysmatch" $line]"
did you mean $todaysdate ?!
same goes for "set end [string first "$todaysmatch*STATUS" $line]"

btw. "string first string1 string2 ?startIndex?" it will only search for strings, not for patterns (wildcards). not sure about that, but I wouldn't count on it!
ah yes, your proc will send an empty line to the server for each line without a match. you will not see it, because the server will most likely discard it, but it will flush unneccessary queues (of course only, if you disabled the same element check for server queue).

for the string extraction I reommned more somthing like this:

Code: Select all

set re "$todaysdate(.*)STATUS"
if { [regexp $re $line {} served] } {
   serve...
}
depending how many times "STATUS" is within that line, you might have to use (.{10,15}) to limit the match between the date STATUS to a specified range of characters.
read http://forum.egghelp.org/viewtopic.php?t=4319 and http://www.tcl.tk/man/tcl8.4/TclCmd/re_syntax.htm for more infos.
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...
Locked