Using this as a construct, this would be your news parser to show all the news.<speechles> !webby http://www.casafree.com/modules/news/ --regexp <div class="articletitre"><a href.*?>.*?<a href='(.*?)'>(.*?)</a>.*?<div class="itemBody">(.*?)</div>--
<sp33chy> regexp: capture1 ( http://www.casafree.com/modules/news/ar ... ryid=44181 )
<sp33chy> regexp: capture2 ( France : ouverture du 32e Festival International de films de femmes de Créteil )
<sp33chy> regexp: capture3 ( La 32e édition du Festival international de films de femmes de Créteil se déroule depuis vendredi à la Maison des Arts de Créteil, et prendra fin le 11 avril, rapporte un site web français spécialisé dans les affaires culturelles. )
Code: Select all
set casafreenews [regexp -inline {<div class="articletitre"><a href.*?>.*?<a href='(.*?)'>(.*?)</a>.*?<div class="itemBody">(.*?)</div>} $html]
foreach {junk url title description} $casafreenews {
puthelp "privmsg $chan :\002$title\002: $description @ $url"
}
Code: Select all
set casafreenews [regexp -inline {<div class="articletitre"><a href.*?>.*?<a href='(.*?)'>(.*?)</a>.*?<div class="itemBody">(.*?)</div>} $html]
foreach {junk url title description} $casafreenews {
if {[info exists ::casaLast] && [string equal $url $::casaLast]} {
break
}
puthelp "privmsg $chan :\002$title\002: $description @ $url"
}
set ::casaLast [lindex $casafreenews 1]
Code: Select all
bind pub - !news pub:news
proc pub:news {nick host hand chan arg} {
set lien "http://www.casafree.com/modules/news/"
set http [http::config -useragent mozilla]
set http [http::geturl $lien -timeout [expr 1000 * 10]]
set html [http::data $http]
set casafreenews [regexp -inline {<div class="articletitre"><a href.*?>.*?<a href='(.*?)'>(.*?)</a>.*?<div class="itemBody">(.*?)</div>} $html]
foreach {junk url title description} $casafreenews {
if {[info exists ::casaLast] && [string equal $url $::casaLast]} {
break
}
puthelp "privmsg $chan :\002$title\002: $description @ $url"
}
set ::casaLast [lindex $casafreenews 1]
}
Code: Select all
namespace eval news {}
setudef flag nopubnews
set news(pref) "!"
set news(commands) "news"
set news(time) 30
set news(page) http://www.casafree.com/modules/news/
set news(version) "1.0"
package require http
foreach bind [split $news(commands) " "] {
bind pub -|- $news(pref)$bind ::news::pub
bind msg -|- $news(pref)$bind ::news::msg
}
proc ::news::msg {nick uhost hand arg} {
::news::news $nick $uhost $hand $nick $arg
}
proc ::news::pub {nick uhost hand chan arg} {
if {[channel get $chan nopubnews]} return
::news::news $nick $uhost $hand $chan $arg
}
proc ::news::news {nick uhost hand chan arg} {
global news lastbind
set arg [lindex [split $arg] 0]
set agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
set news(host,$uhost) 1
set news(timer,$uhost) [utimer $news(time) [list ::news::reset $uhost ] ]
set news_tok [::http::config -useragent $agent]
set news_tok [::http::geturl $news(page) -timeout 30000]
set html [::http::data $news_tok]
::http::cleanup $news_tok
set casafreenews [regexp -inline {<div class="articletitre"><a href.*?>.*?<a href='(.*?)'>(.*?)</a>.*?<div class="itemBody">(.*?)</div>} $html]
foreach {junk url title description} $casafreenews {
puthelp "privmsg $chan :\[ $title \]: $description"
}
return
}
proc ::news::reset { uhost } {
global news
catch {killutimer $news(timer,$uhost)}
catch {unset news(timer,$uhost)}
catch {unset news(host,$uhost)}
}
putlog "news.tcl v$news(version) loaded."
Code: Select all
# Puh Rum Pum Pum Pum
package require http
setudef flag nopubnews
namespace eval news {
# config
set ary(pref) "!"
set ary(commands) "news"
set ary(throttle) 2
set ary(throttle_time) 30
set ary(bind_time) "30*"
set ary(page) http://www.casafree.com/modules/news/
set ary(regex) {<div class="articletitre"><a href.*?>.*?<a href='(.*?)'>(.*?)</a>.*?<div class="itemBody">(.*?)</div>}
set ary(max_bot) 5
set ary(max_user) 5
set ary(version) "2.0"
}
# binds
foreach bind [split $::news::ary(commands)] {
bind pub -|- "$::news::ary(pref)$::news::ary(commands)" ::news::pub_
bind msg -|- "$::news::ary(pref)$::news::ary(commands)" ::news::msg_
}
bind time - $::news::ary(bind_time) ::news::magic_
namespace eval news {
# main - time bind - magic
proc magic_ {args} {
news_ $::botnick [getchanhost $::botnick] $::botnick "all" "magic"
}
# main - msg bind - notice
proc msg_ {nick uhost hand arg} {
news_ $nick $uhost $hand $nick "notice"
}
# main - pub bind - privmsg
proc pub_ {nick uhost hand chan arg} {
if {[channel get $chan nopubnews]} { return }
news_ $nick $uhost $hand $chan "privmsg"
}
# sub - give news
proc news_ {nick uhost hand chan arg} {
if {[throttle_ $uhost,$chan,news $::news::ary(throttle_time)]} {
putserv "$arg $chan :$nick, you have been Throttled! Your going too fast and making my head spin!"
}
set a "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
set t [::http::config -useragent $a]
catch { set t [::http::geturl $::news::ary(page) -timeout 30000] } error
# error condition 1, socket error or other general error
if {![string match -nocase "::http::*" $error] && ![isbotnick $nick]} {
putserv "$arg $chan :[string totitle [string map {"\n" " | "} $error]] \( $::news::ary(page) \)"
return
}
# error condition 2, http error
if {![string equal -nocase [::http::status $t] "ok"] && ![isbotnick $nick]} {
putserv "$arg $chan :[string totitle [::http::status $t]] \( $::news::ary(page) \)"
return
}
set html [::http::data $t]
::http::cleanup $t
set casafreenews [regexp -all -inline "$::news::ary(regex)" $html]
set c 0
foreach {junk url title description} $casafreenews {
incr c
if {[isbotnick $nick]} {
if {$c > $::news::ary(max_bot) || ([info exists ::casaLast] && [string equal $url $::casaLast])} { break }
} elseif {$c > $::news::ary(max_user)} { break }
if {![string equal "magic" $arg]} {
puthelp "$arg $chan :\[ [mapit_ $title] \]: [mapit_ $description] @ $url"
} else {
foreach ch [channels] {
if {[channel get $ch nopubnews]} { continue }
puthelp "$arg $ch :\[ [mapit_ $title] \]: [mapit_ $description] @ $url"
}
}
}
if {[string equal "magic" $arg]} {
set ::casaLast [lindex $casafreenews 1]
}
}
# sub - map it
proc mapit_ {t} { return [string map [list "'" "'"] $t] }
# Throttle Proc (slightly altered, super action missles) - Thanks to user
# see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc throttle_ {id seconds} {
global ::news::throttle
if {[info exists ::news::throttle($id)]&&[lindex $::news::throttle($id) 0]>[clock seconds]} {
set ::news::throttle($id) [list [lindex $::news::throttle($id) 0] [set value [expr {[lindex $::news::throttle($id) 1] +1}]]]
if {$value > $::news::ary(throttle)} { set id 1 } { set id 0 }
} {
set ::news::throttle($id) [list [expr {[clock seconds]+$seconds}] 1]
set id 0
}
}
# delete expired entries every 10 minutes
bind time - ?0* throttleclean_
proc throttleclean_ {args} {
global ::news::throttle
set now [clock seconds]
foreach {id time} [array get ::news::throttle] {
if {[lindex $time 0]<=$now} {unset ::news::throttle($id)}
}
}
}
putlog "news.tcl v$::news::ary(version) loaded."
Code: Select all
Tcl error [throttleclean_]: invalid command name "throttleclean_"
Code: Select all
Cannot post the code, this forum renders the html elements even within [c o d e] tags.. quite lame
Code: Select all
#change this
set ary(bind_time) "30*"
#to this
set ary(bind_time) "00*"
Oh ho ho.. perhaps I should've tested that timer part. I realize the problem, and to make up for it I've added full configuration into the script. Check out the new config below:neoclust wrote:thanks man, i changed the time by 5 minutes to see if the timer will trigger the action to automatically publish the news on the channel but in vain
Code: Select all
namespace eval news {
# config - make your changes here
# trigger character
set ary(pref) "!"
# command used to reply to user
# this can be a list of space delimited commands
set ary(commands) "news"
# amount user can issue before throttle
set ary(throttle) 2
# throttle time
set ary(throttle_time) 30
# time to announce new news items
# this can be a list of space delimited time binds.
# the one you wish to use for bind_time uncommented.
# set ary(bind_time) "00* 15* 30* 45*" ; # every 15 minutes
# set ary(bind_time) "00* 30*" ; # every 30 minutes
set ary(bind_time) "00*" ; # every 60 minutes at exactly the start of the hour
# url to news page
set ary(page) http://www.casafree.com/modules/news/
# parsing regex used to gather news
set ary(regex) {<div class="articletitre"><a href.*?>.*?<a href='(.*?)'>(.*?)</a>.*?<div class="itemBody">(.*?)</div>}
# max amount of news items to announce
set ary(max_bot) 5
# max amount of news items for users
set ary(max_user) 5
# display format for news messages, variables are: %description, %title, %url
# these can be used and will be replaced with actual values, newline (\n) will
# let you span multiple lines if you wish. If something is too long it will
# be cut off, be aware of this... use colors, bold, but remember to \escape any
# special tcl characters.
set ary(display_format) "\[\002%title\002\] %url\n%description"
# script version
set ary(version) "2.2"
}
Get the new script HERE and have a fun.<speechles> !news
<sp33chy> [Grande-Bretagne : L'économie britannique progresserait plus rapidement que la majorité des pays du G7 selon l'OCDE] http://www.casafree.com/modules/news/ar ... ryid=44326
[5:17pm] [sp33chy] L'économique britannique devrait enregistrer au premier semestre de 2010, une croissance plus rapide que la majorité des pays du G7, a indiqué un rapport de l'Organisation de coopération et de développement économiques (OCDE) relayé par la presse britannique.
<sp33chy> [Israël est la principale menace à la paix au Moyen-Orient , dit le PM turc] http://www.casafree.com/modules/news/ar ... ryid=44328
<sp33chy> Israël est la principale menace pour la paix au Moyen-Orient, a indiqué mercredi le Premier ministre turc Recep Tayyip Erdogan, qui est actuellement en visite à Paris.
<sp33chy> [UE - Afrique : : Les compagnies aériennes de 11 pays africains interdites de vol en Europe] http://www.casafree.com/modules/news/ar ... ryid=44327
<sp33chy> La Commission européenne a décidé d'interdire de vol en Europe 278 compagnies aériennes dont celles de 11 pays africains, annonce un communiqué publié mercredi à Bruxelles.
..a short while later..
<sp33chy> [Maroc : Plus de 1200 personnes ont bénéficié des services du Samusocial Casablanca en 2009] http://www.casafree.com/modules/news/ar ... ryid=44329
<sp33chy> 1217 personnes recueillies dans la rue ont bénéficié, en 2009, des services du Centre d'hébergement du service d'aide mobile d'urgence social (Samusocial) de Casablanca.
Code: Select all
[23:31:29] *** Eggy (lamestxpa@network.org) has left #test (Left all channels)
[23:31:45] *** Eggy (lamestxih@network.org) has joined #test
[23:35:03] (Eggy): [Russie - USA : Moscou et Washington déterminés à adopter de nouvelles sanctions contre l'Iran] http://www.casafree.com/modules/news/article.php?storyid=44370
[23:35:06] (Eggy): Le président américain Barack Obama et son homologue russe Dimitri Medvedev ont réaffirmé jeudi à Prague leur détermination à adopter une nouvelle série de sanctions contre l'Iran si ce pays refusait de mettre fin à son programme nucléaire.
[23:35:12] (Eggy): [France : La COPEAM veut avancer dans la concrétisation de ses projets pour l'émergence d'un paysage audiovisuel méditerranéen] http://www.casafree.com/modules/news/article.php?storyid=44369
[23:35:15] (Eggy): La 17ème Conférence Permanente de l'Audiovisuel Méditerranéen (COPEAM) s'ouvre jeudi à Paris avec l'ambition "d'aller plus loin" dans la concrétisation de ses projets phares destinés à contribuer à l'émergence d'un paysage audiovisuel méditerranéen.
[08:14:38] (neoclust): huh