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.

var help

Old posts that have not been replied to for several years.
Locked
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

var help

Post by NewzUK »

Hi, I made this script to retrieve website data at timed intervals, but I'm trying to make it so it will not send anything to the channel if the var $rtr hasn't changed since the last check...would appreciate any help - thanks!

Code: Select all

    proc pub:rtr { nick uhost handle channel arg } {
    set sock [egghttp:geturl http://www.myurl.com/ getrtr]
    return 1
}  

proc getrtr {sock} {
    global rtrurl
    set headers [egghttp:headers $sock]
    set body [egghttp:data $sock]
  
    foreach line [split $body \n] {
    if {[string match "*52_*" $line]} {
    set rtr [gettok $line 2 62]
    set rtr [gettok $rtr 0 60]
    set rtrurl [gettok $line 5 34]
    putserv "PRIVMSG #channel :/0034,4 /0031,15 $rtr /00314,14 /003"
  }
 }
}
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Re: var help

Post by strikelight »

NewzBoy wrote:Hi, I made this script to retrieve website data at timed intervals, but I'm trying to make it so it will not send anything to the channel if the var $rtr hasn't changed since the last check...would appreciate any help - thanks!

Code: Select all

    proc pub:rtr { nick uhost handle channel arg } {
    set sock [egghttp:geturl http://www.myurl.com/ getrtr]
    return 1
}  

proc getrtr {sock} {
    global rtrurl
    set headers [egghttp:headers $sock]
    set body [egghttp:data $sock]
  
    foreach line [split $body \n] {
    if {[string match "*52_*" $line]} {
    set rtr [gettok $line 2 62]
    set rtr [gettok $rtr 0 60]
    set rtrurl [gettok $line 5 34]
    putserv "PRIVMSG #channel :/0034,4 /0031,15 $rtr /00314,14 /003"
  }
 }
}
You will need to store a copy into a global variable and check against it then...

Code: Select all

proc getrtr {sock} {
    global rtrurl rtrold
    set headers [egghttp:headers $sock]
    set body [egghttp:data $sock]
    egghttp:cleanup $sock

    foreach line [split $body \n] {
      if {[string match "*52_*" $line]} {
        set rtr [gettok $line 2 62]
        set rtr [gettok $rtr 0 60]
        set rtrurl [gettok $line 5 34]
        if {![info exists rtrold] || ($rtr != $rtrold)} {
          putserv "PRIVMSG #channel :/0034,4 /0031,15 $rtr /00314,14 /003"
        } else {
          set rtrold $rtr
        }
      }
    }
}
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

thanks strikelight - since I posted that, I added a couple of else/elseif's to deal with some content in the $var :

if {[string is upper $rtr]} {
putserv "PRIVMSG #channel :4,4 0,4 [gettime +0]ET $rtr "
} elseif {[string match *-* $rtr]} {
putserv "PRIVMSG #Newsroom2 :7,7 1,15 [gettime +0]ET $rtr "
} else {
putserv "PRIVMSG #Newsroom2 :4,4 1,15 [gettime +0]ET $rtr "

will that mess up the:

} else {
set rtrold $rtr

? thanks again
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

actually, I think I answered my own question there - just added the setting of the old var to the new one after each of the else/if's.

thanks again for the help, and will see how it goes!
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Actually, dunno what I was thinking when I posted that...

But...

Change the:

Code: Select all

} else {
  set rtrold $rtr
}
To just:

Code: Select all

  set rtold $rtr
}
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

one more question if I could - with regards to 'string is upper', I've got a different style to print to the channel if the text is upper, however I've found if there are numerals or other symbols involved, it dosn't seem to work as the upper line, and sends it in the 'else' e.g.:

POWERFUL EXPLOSION HEARD IN CENTRAL BAGHDAD - REUTERS WITNESSES

did not get recognised as an 'is upper'.

any ideas on how it could do so if all the letters are upper no matter if there are other symbols in the line?

thanks.
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

strikelight wrote:Actually, dunno what I was thinking when I posted that...

But...

Change the:

Code: Select all

} else {
  set rtrold $rtr
}
To just:

Code: Select all

  set rtold $rtr
}
cool got that one thanks :)
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

NewzBoy wrote:any ideas on how it could do so if all the letters are upper no matter if there are other symbols in the line?

Code: Select all

if {![string match {*[a-z]*} $str]} {
  # $str does not contain any lowercase letters
}
Have you ever read "The Manual"?
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

thanks user - it's working great!

one more thing about strings (slowly getting through the list!)

sometimes when retrieving text from a website, it puts extra characters with certain characters, like this for '&':

S&P Affirms ANZ National Bank Ratings

it puts 'amp;' with the '&'
so what I'm wondering is if I can specify to remove the amp; part, if it appears in a string, like $remove(%var,amp;) would do in mIRC...
thanks again.
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Something like this should work

Code: Select all

set str [string map {"&" "\&"} $str]
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

that's working - thanks alot =)
#Newsroom - Where News & Markets Connect
http://www.inewsroom.net
#Newsroom on irc.othernet.org
Locked