| View previous topic :: View next topic |
| Author |
Message |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Fri Jan 13, 2006 1:57 pm Post subject: check site |
|
|
it is a news script, but I want to see latest news on channel only when site is updated.. can someone help?
| Code: | package require http
bind pub - !news www:news4
proc www:news4 {nick host handle chan text} {
set token [::http::geturl http://www.eurosport.com/football/ -timeout 10000]
set status [::http::status $token]
if {$status!="ok"} {
switch -exact -- [string tolower $status] {
reset { puthelp "PRIVMSG $chan :error: server connection was reset." }
timeout { puthelp "PRIVMSG $chan :error: server timeout (10 seconds)" }
default { puthelp "PRIVMSG $chan :unknown server error occured" }
}
::http::cleanup $token; return
}
if {[::http::ncode $token]=="404"} {
::http::cleanup $token
puthelp "PRIVMSG $chan :Sorry, error 404"; return
}
set data [::http::data $token]; ::http::cleanup $token
set all [regexp -all -inline -nocase -- {class="storyshortmaintitle">(.*?)</a>} $data]
set count 1
foreach {tmp news} $all {
if {$count=="2"} {return}
puthelp "PRIVMSG $chan :www.eurosport.com - $news"
incr count
}
} |
|
|
| Back to top |
|
 |
avilon Halfop

Joined: 13 Jul 2004 Posts: 64 Location: Germany
|
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Sat Jan 14, 2006 7:07 am Post subject: |
|
|
| Yes, thanks, but I need to know, because all sites do not have a rss.. if it is too hard, where should I put the timer, to post latest news in every hour? |
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Mon Jan 16, 2006 6:10 am Post subject: |
|
|
| Anyone can help with timer? |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Mon Jan 16, 2006 6:27 am Post subject: |
|
|
You can use the time bind to call a proc every hour, something like:
| Code: | bind time - "00 *" foo
proc foo args {
# call the news proc
www:news4 arg1 arg2...
} |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Wed Jan 18, 2006 7:37 am Post subject: |
|
|
Ok I tried to write, but it doesn`t work, i tried with normal site, with regexps which works on other scripts, here is a code with example site, where is mistake? Bot do not reply on trigger...
| Code: | package require http
bind pub - !test www:test
proc www:test {nick host handle chan text} {
set lastnews ""
set lastnews $match
set data [http::data http::geturl www.example.com]]
regexp {<td width="65%" class="medium">(.*?)</td><td align="right"} $data data match]
if {$lastnews != ""} {
puthelp "PRIVMSG $chan :test - $match"
}
set lastnews $macz
}
|
|
|
| Back to top |
|
 |
norway27 Voice
Joined: 06 Jan 2006 Posts: 7
|
Posted: Thu Jan 19, 2006 12:25 pm Post subject: Re: check site |
|
|
| FcLan wrote: | it is a news script, but I want to see latest news on channel only when site is updated.. can someone help?
| Code: | package require http
bind pub - !news www:news4
proc www:news4 {nick host handle chan text} {
set token [::http::geturl http://www.eurosport.com/football/ -timeout 10000]
set status [::http::status $token]
if {$status!="ok"} {
switch -exact -- [string tolower $status] {
reset { puthelp "PRIVMSG $chan :error: server connection was reset." }
timeout { puthelp "PRIVMSG $chan :error: server timeout (10 seconds)" }
default { puthelp "PRIVMSG $chan :unknown server error occured" }
}
::http::cleanup $token; return
}
if {[::http::ncode $token]=="404"} {
::http::cleanup $token
puthelp "PRIVMSG $chan :Sorry, error 404"; return
}
set data [::http::data $token]; ::http::cleanup $token
set all [regexp -all -inline -nocase -- {class="storyshortmaintitle">(.*?)</a>} $data]
set count 1
foreach {tmp news} $all {
if {$count=="2"} {return}
puthelp "PRIVMSG $chan :www.eurosport.com - $news"
incr count
}
} |
|
It would be great if someone could show me how this script can read from 2 classes and post it in a chan..this script reads from one-> class="storyshortmaintitle"
Lets say the 2 classes are "storyshortmaintitle" and "story"
like this:
<user>!news
<bot> "storyshortmaintitle"
<bot> "story"
thx |
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Thu Jan 19, 2006 2:21 pm Post subject: |
|
|
I tried to make it also, but doesn`t work, don`t know why.. 0 errors in tcl..
| Code: | package require http
bind pub - !news www:news4
proc www:news4 {nick host handle chan text} {
set token [::http::geturl http://www.eurosport.com/football/ -timeout 10000]
set status [::http::status $token]
if {$status!="ok"} {
switch -exact -- [string tolower $status] {
reset { puthelp "PRIVMSG $chan :error: server connection was reset." }
timeout { puthelp "PRIVMSG $chan :error: server timeout (10 seconds)" }
default { puthelp "PRIVMSG $chan :unknown server error occured" }
}
::http::cleanup $token; return
}
if {[::http::ncode $token]=="404"} {
::http::cleanup $token
puthelp "PRIVMSG $chan :Sorry, error 404"; return
}
set data [::http::data $token]; ::http::cleanup $token
set all [regexp -all -inline -nocase -- {class="storyshortmaintitle">(.*?)</a>} $data]
set count 1
foreach {tmp news} $all {
if {$count=="2"} {return}
}
set all2 [regexp -all -inline -nocase -- {class="(.*?)</a>} $data]
set count 1
foreach {tmp news2} $all2 {
if {$count=="2"} {return}
incr count
}
puthelp "PRIVMSG $chan :www.eurosport.com - $news - $news2"
} |
|
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Fri Jan 20, 2006 10:18 am Post subject: |
|
|
| Any ideas why mroe than 1 regexp doesn`t work? i have no tcl errors.. bot do not send msg |
|
| Back to top |
|
 |
norway27 Voice
Joined: 06 Jan 2006 Posts: 7
|
Posted: Fri Jan 20, 2006 12:18 pm Post subject: |
|
|
| FcLan wrote: | | Any ideas why mroe than 1 regexp doesn`t work? i have no tcl errors.. bot do not send msg |
I got it to work a little bit if I typed in the name of the same class in both places... |
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Fri Jan 20, 2006 1:46 pm Post subject: |
|
|
| Can you show me? |
|
| Back to top |
|
 |
norway27 Voice
Joined: 06 Jan 2006 Posts: 7
|
Posted: Sat Jan 21, 2006 6:20 pm Post subject: |
|
|
Something like this:
| Code: | package require http
bind pub - !news www:news4
proc www:news4 {nick host handle chan text} {
set token [::http::geturl http://www.webpage.com -timeout 10000]
set status [::http::status $token]
if {$status!="ok"} {
switch -exact -- [string tolower $status] {
reset { puthelp "PRIVMSG $chan :error: server connection was reset." }
timeout { puthelp "PRIVMSG $chan :error: server timeout (10 seconds)" }
default { puthelp "PRIVMSG $chan :unknown server error occured" }
}
::http::cleanup $token; return
}
if {[::http::ncode $token]=="404"} {
::http::cleanup $token
puthelp "PRIVMSG $chan :Sorry, error 404"; return
}
set data [::http::data $token]; ::http::cleanup $token
set all [regexp -all -inline -nocase -- {class="class_story">(.*?)</a>} $data]
set count 1
foreach {tmp news} $all {
if {$count=="2"} {return}
}
set all2 [regexp -all -inline -nocase -- {class="class_story"(.*?)</a>} $data]
set count 1
foreach {tmp news2} $all2 {
if {$count=="2"} {return}
incr count
}
puthelp "PRIVMSG $chan :www.webpage.com - $news"
puthelp "PRIVMSG $chan :www.webpage.com - $news2"
} |
It was messy..got alot of html code too with it...but the bot did respond with
line 1: topic
Line 2: topic & story
I hope someone can try to fix this code because I have no idea what to do! |
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Sat Jan 21, 2006 7:00 pm Post subject: |
|
|
| Code: | | Tcl error [www:news4]: can't read "news": no such variable |
|
|
| Back to top |
|
 |
norway27 Voice
Joined: 06 Jan 2006 Posts: 7
|
Posted: Sat Jan 21, 2006 7:07 pm Post subject: |
|
|
| FcLan wrote: | | Code: | | Tcl error [www:news4]: can't read "news": no such variable |
|
Yes I got that too sometimes..I had to search through the page for another class and then change the name of the class in the script until I got it right.. |
|
| Back to top |
|
 |
FcLan Halfop
Joined: 30 Sep 2005 Posts: 64 Location: Poland
|
Posted: Sat Jan 21, 2006 7:16 pm Post subject: |
|
|
| I need it for football results, so I need few veriables .. ;/ |
|
| Back to top |
|
 |
|