|
Joined: Aug 2004
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Aug 2004
Posts: 10 |
I got an RSS feed reader script and it is a alias and it works great. When i call the alias how can i check if the RSS feed is ready.. on 1:text:!ww:#:{ %rss.ready = 0 rssfeed http://www.webwereld.nl/rss/trillian.rss msg $chan ( $hget(rssfeed,<link>2) ) $hget(rssfeed,<title>2) } As you can see in the RSSfeed alias when it is ready it sets %rss.ready = 1 So i must wait until this variable is 1 ... How can i do this? /rssfeed
Grabs the tag and data of each RSS item from a specified RSS feed and saves it in a hash table named rssfeed. ;; RSS Feed Grabber ;; by bunkahumpa - bh@scriptsurge.org - irc.GameSurge.net #script ;; -> function: grabs the tag and data of each RSS item and saves it in a hash table named rssfeed. ;; -> usage: /rssfeed http://www.address.to/rss/feed (use the full URL - INCLUDING http://)
; $grabdata -> grabs whatever is between <blah></blah> ; (the tags must be the same, usually found in RSS feeds) ; it returns the tag name and the stuff inside it seperated by $chr(255) alias -l grabdata { if ($regex($1-,(<([^>]+)>)(.+)</\2>)) return $regml(1) $+ $chr(255) $+ $regml(3) }
alias rssfeed { if ($1 == $null) return else { if ($left($1,7) != http://) echo $color(text) -a Incorrect URL format, please include http:// at the beginning. else { if ($sock(rssfeed)) sockclose rssfeed ; grab the host from $1 and connect to it sockopen rssfeed $gettok($1,2,47) 80 ; store $1 in a sockmark of the rssfeed socket sockmark rssfeed $1 echo $color(text) -a Attempting to connect to host $gettok($sock(rssfeed).mark,2,47) and GET $iif(!$gettok($sock(rssfeed).mark,3-,47),/,$gettok($sock(rssfeed).mark,3-,47)) } } }
on *:sockopen:rssfeed:{ if ($sockerr > 0) { echo $color(text) -a Could not connect to host $gettok($sock($sockname).mark,2,47) and GET $iif(!$gettok($sock($sockname).mark,3-,47),/,$gettok($sock($sockname).mark,3-,47)) return } ; if the hash table rssfeed exists from a previous execution, clear it if ($hget(rssfeed)) hfree rssfeed ; GET the page using the path after the host in the sockmark sockwrite -n $sockname GET / $+ $gettok($sock($sockname).mark,3-,47) HTTP/1.1 ; specify the host as well from the sockmark sockwrite -n $sockname Host: $gettok($sock($sockname).mark,2,47) sockwrite -n $sockname Connection: keep-alive sockwrite -n $sockname }
on *:sockread:rssfeed:{ if ($sockerr > 0) return :nextread sockread %temp if (%temp == $null) var %temp = - if ($sockbr == 0) { echo $color(text) -a 0 bytes being read by socket. ( $+ $hget(rssfeed,0).item $iif($hget(rssfeed,0).item == 1,item,items) saved in hash table rssfeed) %rss.ready = 1 return } if ((</rdf:RDF> isin %temp) || (</rss> isin %temp)) { ; if the end of an RSS file is found, end it sockclose $sockname if (%temp) unset %temp echo $color(text) -a END OF FEED DETECTED: $hget(rssfeed,0).item $iif($hget(rssfeed,0).item == 1,item,items) saved in hash table rssfeed. %rss.ready = 1 return } if ($grabdata(%temp)) { ; if it matches an RSS item type (see the grabdata alias above) store the tag in %item var %item = $gettok($grabdata(%temp),1,255) ; if there is no item in the hash table that matches that tag, make it the first ; -> e.g. <title>1 if (!$hfind(rssfeed,%item $+ *,0,w)) hadd -m rssfeed %item $+ 1 $gettok($grabdata(%temp),2,255) ; if not, loop through it items in the hash table and find the highest matching tag ; then save it as an item with a number of one higher than the highest ; -> e.g. there's a <title>1 so store it as <title>2 ; and break out of the loop by setting the looping var higher than the while condition else { var %x = 1 while (%x <= $hget(rssfeed,0).item) { if ($hfind(rssfeed,%item $+ *,0,w)) { var %item = %item $+ $calc($ifmatch + 1) hadd -m rssfeed %item $gettok($grabdata(%temp),2,255) var %x = $hget(rssfeed,0).item } inc %x } } } goto nextread }
on *:sockclose:rssfeed:{ ; if the socket is closed by the remote host say so echo $color(text) -a Socket closed by host (couldn't find end of feed, might not be an RSS feed or one that does not follow standards). ( $+ $hget(rssfeed,0).item $iif($hget(rssfeed,0).item == 1,item,items) saved in hash table rssfeed) }
;--------------------------------------------------
menu status,channel { - HashDump .$submenu($hashdumpmenu($1)) - }
alias hashdumpmenu { if ($hget($1) == $null) return return $hget($1) ( $+ $hget($1,0).item $+ ): /dumphash $hget($1) }
; DumpHash(TableName) alias dumphash { echo -a $chr(160) echo -a 03<--- $1 --->
var %i = $hget($1,0).item while (%i > 0) { var %key = $hget($1,%i).item echo -a %key $str($chr(160),$calc(15 - $len(%key))) -> $hget($1,%key) dec %i }
echo -a 03<--- $1 ---> echo -a $chr(160) }
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
Yu could set a %variable on the ttext event on 1:text:!ww:#:{
%rss.chan = #
%rss.ready = 0
rssfeed http://www.webwereld.nl/rss/trillian.rss
} and put a conditional inside the sockread event on *:sockread:rssfeed:{
;........truncated for the posting. :)
;.....
if ((</rdf:RDF> isin %temp) || (</rss> isin %temp)) {
; if the end of an RSS file is found, end it
sockclose $sockname
if (%temp) unset %temp
echo $color(text) -a END OF FEED DETECTED: $hget(rssfeed,0).item $iif($hget(rssfeed,0).item == 1,item,items) saved in hash table rssfeed.
%rss.ready = 1
[color:blue] if %rss.chan { msg $v1 ( $hget(rssfeed,<link>2) ) $hget(rssfeed,<title>2) | unset %rss.chan }[/color]
return
}
;........
;.....
}
|
|
|
|
Joined: Aug 2004
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Aug 2004
Posts: 10 |
Yep could do that... but i'm using this alias to get other newsfeeds with other variable's The text event gets the necessary stuff from the hash table.
So i have to figure out a way to make the text event wait until the hash table is filled (done by the alias)...
|
|
|
|
Joined: Aug 2004
Posts: 10
Pikka bird
|
OP
Pikka bird
Joined: Aug 2004
Posts: 10 |
OK.. started playing around and now it works.. I put a few variables of a new alias in the text event It looks like this now: [color:green] on 1:text:!ww:#:{
%rss.alias = webwereld
%rss.chan = $chan
describe $chan gaat de nieuwste 3 headlines van www.webwereld.nl ophalen...
rssfeed http://www.webwereld.nl/rss/trillian.rss
}[/color] Then i created a new alias with that variable name [color:green] alias webwereld {
msg %rss.chan ( $hget(rssfeed,<link>2) ) $hget(rssfeed,<title>2)
msg %rss.chan ( $hget(rssfeed,<link>3) ) $hget(rssfeed,<title>3)
msg %rss.chan ( $hget(rssfeed,<link>4) ) $hget(rssfeed,<title>4)
unset %rss.*
} [/color] Then i called the alias at the end of the first alias (sort of what Iori said) And the RSS read script is this: [color:green] /rssfeed
Grabs the tag and data of each RSS item from a specified RSS feed and saves it in a hash table named rssfeed.
;; RSS Feed Grabber
;; by bunkahumpa - bh@scriptsurge.org - irc.GameSurge.net #script
;; -> function: grabs the tag and data of each RSS item and saves it in a hash table named rssfeed.
;; -> usage: /rssfeed http://www.address.to/rss/feed (use the full URL - INCLUDING http://)
; $grabdata -> grabs whatever is between <blah></blah>
; (the tags must be the same, usually found in RSS feeds)
; it returns the tag name and the stuff inside it seperated by $chr(255)
alias -l grabdata { if ($regex($1-,(<([^>]+)>)(.+)</\2>)) return $regml(1) $+ $chr(255) $+ $regml(3) }
alias rssfeed {
if ($1 == $null) return
else {
if ($left($1,7) != http://) echo $color(text) -a Incorrect URL format, please include http:// at the beginning.
else {
if ($sock(rssfeed)) sockclose rssfeed
; grab the host from $1 and connect to it
sockopen rssfeed $gettok($1,2,47) 80
; store $1 in a sockmark of the rssfeed socket
sockmark rssfeed $1
echo $color(text) -a Attempting to connect to host $gettok($sock(rssfeed).mark,2,47) and GET $iif(!$gettok($sock(rssfeed).mark,3-,47),/,$gettok($sock(rssfeed).mark,3-,47))
}
}
}
on *:sockopen:rssfeed:{
if ($sockerr > 0) {
echo $color(text) -a Could not connect to host $gettok($sock($sockname).mark,2,47) and GET $iif(!$gettok($sock($sockname).mark,3-,47),/,$gettok($sock($sockname).mark,3-,47))
return
}
; if the hash table rssfeed exists from a previous execution, clear it
if ($hget(rssfeed)) hfree rssfeed
; GET the page using the path after the host in the sockmark
sockwrite -n $sockname GET / $+ $gettok($sock($sockname).mark,3-,47) HTTP/1.1
; specify the host as well from the sockmark
sockwrite -n $sockname Host: $gettok($sock($sockname).mark,2,47)
sockwrite -n $sockname Connection: keep-alive
sockwrite -n $sockname
}
on *:sockread:rssfeed:{
if ($sockerr > 0) return
:nextread
sockread %temp
if (%temp == $null) var %temp = -
if ($sockbr == 0) {
echo $color(text) -a 0 bytes being read by socket. ( $+ $hget(rssfeed,0).item $iif($hget(rssfeed,0).item == 1,item,items) saved in hash table rssfeed)
return
}
if ((</rdf:RDF> isin %temp) || (</rss> isin %temp)) {
; if the end of an RSS file is found, end it
sockclose $sockname
if (%temp) unset %temp
echo $color(text) -a END OF FEED DETECTED: $hget(rssfeed,0).item $iif($hget(rssfeed,0).item == 1,item,items) saved in hash table rssfeed.
[color:orange]%rss.alias[/color]
return
}
if ($grabdata(%temp)) {
; if it matches an RSS item type (see the grabdata alias above) store the tag in %item
var %item = $gettok($grabdata(%temp),1,255)
; if there is no item in the hash table that matches that tag, make it the first
; -> e.g. <title>1
if (!$hfind(rssfeed,%item $+ *,0,w)) hadd -m rssfeed %item $+ 1 $gettok($grabdata(%temp),2,255)
; if not, loop through it items in the hash table and find the highest matching tag
; then save it as an item with a number of one higher than the highest
; -> e.g. there's a <title>1 so store it as <title>2
; and break out of the loop by setting the looping var higher than the while condition
else {
var %x = 1
while (%x <= $hget(rssfeed,0).item) {
if ($hfind(rssfeed,%item $+ *,0,w)) {
var %item = %item $+ $calc($ifmatch + 1)
hadd -m rssfeed %item $gettok($grabdata(%temp),2,255)
var %x = $hget(rssfeed,0).item
}
inc %x
}
}
}
goto nextread
}
on *:sockclose:rssfeed:{
; if the socket is closed by the remote host say so
echo $color(text) -a Socket closed by host (couldn't find end of feed, might not be an RSS feed or one that does not follow standards). ( $+ $hget(rssfeed,0).item $iif($hget(rssfeed,0).item == 1,item,items) saved in hash table rssfeed)
[color:orange] %rss.alias [/color]
} Thnx for the tip Iori
|
|
|
|
|