Lecteur RSS
#1
Bonsoir à tous.

Au détour d'une conversation, j'ai eu vent d'un script appelé "RSS Feed Reader" pour eggdrop.
Il est disponible à http://www.hawkee.com/snippet/9851/

[quote]Partyline Commands:
  • .rss (Returns a list of commands and syntax)
  • .rss list (Returns the list of feeds being checked by the bot.)
  • .rss add <#chan1,#chan2,#chan3> <name> <logo> <rssfeedlink> (Adds a feed)
  • .rss addxml <#chan1,#chan2,#chan3> <name> <logo> <rssfeedlink> (Adds a xml style feed - Try this if you have trouble with a feed.)
  • .rss delete <name> (Deletes a feed)
  • .rss info <name> (Returns info about a feed)
Voici la source (des fois qu'elle disparaisse) :
TCL
##############################################################################################
##  ##     rssreader.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help    ##  ##
##############################################################################################
## .rss in the party line for commands and syntax. Example Feed Add Below:                  ##
##.rss add #Hawkee hawkee Hawkee http://www.hawkee.com/comment.rss.php?tool_type=snippet_id ##
##############################################################################################
##      ____                __                 ###########################################  ##
##     / __/___ _ ___ _ ___/ /____ ___   ___   ###########################################  ##
##    / _/ / _ `// _ `// _  // __// _ \ / _ \  ###########################################  ##
##   /___/ \_, / \_, / \_,_//_/   \___// .__/  ###########################################  ##
##        /___/ /___/                 /_/      ###########################################  ##
##                                             ###########################################  ##
##############################################################################################
##  ##                             Start Setup.                                         ##  ##
##############################################################################################
namespace eval rssreader {
## Edit textf to change the color/state of the text shown                               ##  ##
  variable textf "\017\00304"
## Edit linkf to change the color/state of the links                                    ##  ##
  variable linkf "\017\037"
## Change usetiny to shorten links with tinyurl. 1 = on , 0 = off                       ##  ##  
  variable usetiny 1
## Edit maxresults to the amount of results you want per query. This will not cause     ##  ##
## You to lose results. It will only spread them out over several querys.               ##  ##
  variable maxresults 2
## Edit checkdelay to change the frequency feed pages are checked. Delay is in minutes. ##  ##
  variable checkdelay 3
## Edit startupdelay to add delay to startup/restart. Delay is in minutes.              ##  ##
  variable startupdelay 2
##############################################################################################
##  ##                           End Setup.                                              ## ##
##############################################################################################   
  bind dcc - rss rssreader::settings
  bind evnt -|- init-server rssreader::loadhash
  bind evnt -|- prerehash rssreader::loadhash
  proc settings {hand idx text} {
    set choice [lindex $text 0]; set channel [lindex $text 1]
    set name [lindex $text 2]; set logo [lindex $text 3]
	set link [lindex $text 4]
	if {[string equal -nocase "add" $choice] && $link != ""} {
	  set deleteinfo [hget "rssreader" $name]
	  if {[set idx [lsearch -glob [timers] "*$deleteinfo*"]] != -1 && $deleteinfo != ""} {
	    killtimer [lindex [lindex [timers] $idx] 2]
	  }
	  hadd "rssreader" "$name" "rssreader::main {$channel $logo $link}"
	  savehash
	  putlog "Added feed $name to $channel as $logo $link"
	  rssreader::main "$channel $logo $link"
	} elseif {[string equal -nocase "addxml" $choice] && $link != ""} {
	  set deleteinfo [hget "rssreader" $name]
	  if {[set idx [lsearch -glob [timers] "*$deleteinfo*"]] != -1 && $deleteinfo != ""} {
	    killtimer [lindex [lindex [timers] $idx] 2]
	  }
	  hadd "rssreader" "$name" "rssreader::type2 {$channel $logo $link}"
	  savehash
	  putlog "Added feed $name to $channel as $logo $link"
	  rssreader::type2 "$channel $logo $link"
	} elseif {[string equal -nocase "list" $choice]} {
	  putlog "\[RSS list\]"
	  set count [hfind "rssreader" "*" 0]; set counter 1
	  while {$count >= $counter} {
	    putlog "[hfind "rssreader" "*" $counter]"
		incr counter
	  }
	} elseif {[string equal -nocase "info" $choice] && $channel != ""} {
	  putlog "[hget "rssreader" $channel]"
	} elseif {[string equal -nocase "delete" $choice] && $channel != ""} {
	  set deleteinfo [hget "rssreader" $channel]
	  hdel "rssreader" $channel
	  savehash
	  if {[set idx [lsearch -glob [timers] "*$deleteinfo*"]] != -1} {
	    killtimer [lindex [lindex [timers] $idx] 2]
		putlog "Removed $channel from RSS"
	  }
	} elseif {[string equal -nocase "timers" $choice]} {
	  putlog [timers]
	} else {
	  putlog "\[RSS Syntax\]"
	  putlog "Add Feed: .rss add <#chan1,#chan2,#chanetc> <name> <logo> <link>"
	  putlog "Add Xml Feed: .rss addxml <#chan1,#chan2,#chanetc> <name> <logo> <link>"
	  putlog "Delete Feed: .rss delete <name>"
	  putlog "Info Feed: .rss info <name>"
	  putlog "List Feeds: .rss list"
	  putlog "Help Feeds: .rss"
    }	
  }
  proc main {text} {
    set chan [lindex $text 0]; set logo [lindex $text 1]; set linker [lindex $text 2]
    set title ""; set link ""; set description ""; set maxcount 1; set json ""
    if {[set idx [lsearch -glob [timers] "*rssreader::main {$chan $logo ${linker}}*"]] != -1} { 
      killtimer [lindex [lindex [timers] $idx] 2] 
    }
    timer $rssreader::checkdelay "rssreader::main {$chan $logo $linker}"
    set rssreaderurl "/ajax/services/feed/load?v=1.0&q=${linker}"
    set rssreadersite "ajax.googleapis.com"; set rssout ""
    if {[catch {set rssreadersock [socket -async $rssreadersite 80]} sockerr]} {
      return 0
    } else {
      puts $rssreadersock "GET $rssreaderurl HTTP/1.0"
      puts $rssreadersock "Host: $rssreadersite"
      puts $rssreadersock "User-Agent: Opera 9.6"
      puts $rssreadersock ""
      flush $rssreadersock
      while {![eof $rssreadersock]} {
        set rssreadervar " [string map {<![CDATA[ "" ]]> "" \$ \002\$\002 \[ \( \] \)} [gets $rssreadersock]] "
		if {[regexp {\"responseStatus\":\s?400} $rssreadervar]} {
		  if {[set idx [lsearch -glob [timers] "*rssreader::main {$chan $logo ${linker}}*"]] != -1} { 
            killtimer [lindex [lindex [timers] $idx] 2] 
          }
		  type2 "$chan $logo $linker"
		  close $rssreadersock
		  return
		} else {
		  regexp {\:\[(\{.*)$} $rssreadervar match rssout
		  set rssout [regexp -all -inline {\{(.*?)\}} $rssout]
		  if {$rssout != ""} {
		    set count 0
		    foreach {match matched} $rssout {
			  incr count
		      set matched [regexp -all -inline {(".*?":".*?"\,)} $match]
              foreach {innermatch innermatched} $matched {
			    regexp  {\"(.*?)\":\".*?\"\,} $innermatch match varname
                regexp  {\".*?\":\"(.*?)\"\,} $innermatch match value
				set value [string map {\$ \002\$\002 \] \002\]\002 \[ \002\[\002} $value]
			    set $varname $value
			  }
			  if {[hfindexact "rsstempold" "${link}" 1] != $link} {
			    if {$title == ""} { set title $description }
				set linked $link
				if {$rssreader::usetiny} { set linked [tiny $link] }
				if {$maxcount <= $rssreader::maxresults} {
			      putserv "PRIVMSG $chan :${logo} ${rssreader::textf}[dehex $title] ${rssreader::linkf}$linked"
			      incr maxcount
				  hadd "rsstempnew" $link 1
				} 
			  }
            }
		    hfree rsstempold
		    hcopy rsstempnew rsstempold
          }
		}
      }
	  close $rssreadersock
    } 
  }
  proc type2 {text} {
    set chan [lindex $text 0]; set logo [lindex $text 1]; set linker [lindex $text 2]
    set title ""; set link ""; set description "" 
    if {[set idx [lsearch -glob [timers] "*rssreader::type2 {$chan $logo ${linker}}*"]] != -1} { 
      killtimer [lindex [lindex [timers] $idx] 2] 
    }
    timer $rssreader::checkdelay "rssreader::type2 {$chan $logo $linker}"
	regexp -- {https?\:\/\/(.*?)(\/.*)$} $linker wholematch rsstype2site rsstype2url
	set itemfound 0 ; set maxcount 1
    if {[catch {set rsstype2sock [socket -async $rsstype2site 80]} sockerr]} {
      return 0
    } else {
      puts $rsstype2sock "GET $rsstype2url HTTP/1.0"
      puts $rsstype2sock "Host: $rsstype2site"
      puts $rsstype2sock "User-Agent: Opera 9.6"
      puts $rsstype2sock ""
      flush $rsstype2sock
      while {![eof $rsstype2sock]} {
        set rsstype2var " [string map {<![CDATA[ "" ]]> "" \$ \002\$\002 \[ \( \] \)} [gets $rsstype2sock]] "	
        if {[string match {*<item>*} $rsstype2var]} { set itemfound 1 }
		if {[regexp {<title>(.*?)(?:<\/title>|$)} $rsstype2var match title]} { }
		if {[regexp {<link>(.*?)(?:<\/link>|$)} $rsstype2var match link]} {
		  if {[hfindexact "rsstempold" "${link}" 1] != $link} {
			if {$itemfound} {
			  if {$maxcount <= $rssreader::maxresults} {
			    set linked $link
				if {$rssreader::usetiny} { set linked [tiny $link] }
			    putserv "PRIVMSG $chan :${logo} ${rssreader::textf}[dehex $title] ${rssreader::linkf}$linked"
				incr maxcount
				hadd "rsstempnew" $link 1
			  } 
			}
		  }
		}
      }
	  set itemfound 0
      hfree rsstempold
	  hcopy rsstempnew rsstempold
	  close $rsstype2sock
    } 
  }
  proc tiny {link} {
    set tinysite tinyurl.com
    set tinyurl /api-create.php?url=[urlencode ${link}]
    if {[catch {set tinysock [socket -async $tinysite 80]} sockerr]} {
      putlog "$tinysite $tinyurl $sockerr error"
      return $link
    } else {
      puts $tinysock "GET $tinyurl HTTP/1.0"
      puts $tinysock "Host: $tinysite"
      puts $tinysock "User-Agent: Opera 9.6"
      puts $tinysock ""
      flush $tinysock
      while {![eof $tinysock]} {
        set tinyvar " [gets $tinysock] "
        if {[regexp {(http:\/\/.*)} $tinyvar match tinyresult]} {
          close $tinysock
          return $tinyresult
        }
      }
      close $tinysock
      return $link
    }
  }
  proc hex {decimal} { return [format %x $decimal] }
  proc decimal {hex} { return [expr 0x$hex] }
  proc dehex {string} {
    regsub -all {^\{|\}$} $string "" string
    set string [subst [regsub -nocase -all {\\u([a-f0-9]{4})} $string {[format %c [decimal \1]]}]]
    set string [subst [regsub -nocase -all {\%([a-f0-9]{2})} $string {[format %c [decimal \1]]}]]
    set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
    set string [subst [regsub -nocase -all {\&#x([0-9]{2});} $string {[format %c [decimal \1]]}]]
    set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002 &ndash; – &raquo; \
    » &laquo; « &Uuml; Ü &uuml; ü &Aacute; Á &aacute; á &Eacute; É &eacute; é &Iacute; Í &iacute; \
    í &Oacute; Ó &oacute; ó &Ntilde; Ñ &ntilde; ñ &Uacute; Ú &uacute; ú &aelig; æ &nbsp; " " &apos; \' \
	\( \002\(\002 \) \002\)\002 \{ \002\{\002 \} \002\}\002} $string]
    return $string
  }
  proc urlencode {string} {
    regsub -all {^\{|\}$} $string "" string
    return [subst [regsub -nocase -all {([^a-z0-9\+])} $string {%[format %x [scan "\\&" %c]]}]]
  }
  proc hadd {hashname shoot hashdata } {
    global $hashname
    set ${hashname}($shoot) $hashdata
  }
  proc hget {hashname shoot} {
    upvar #0 $hashname hgethashname
	if {[info exists hgethashname($shoot)]} {
	  return $hgethashname($shoot)
	} else {
	  return 0
	}
  }
  proc hfind {hashname search value} {
    upvar #0 $hashname hfindhashname
	if {[array exists hfindhashname]} {
	  if {$value == 0} {
	    return [llength [array names hfindhashname $search]]
      } else {
        set value [expr $value - 1]
	    return [lindex [array names hfindhashname $search] $value]
	  }
	}
  }
  proc hfindexact {hashname search value} {
    upvar #0 $hashname hfindhashname
	if {[array exists hfindhashname]} {
	  if {$value == 0} {
	    return [llength [array names hfindhashname -exact $search]]
      } else {
        set value [expr $value - 1]
	    return [lindex [array names hfindhashname -exact $search] $value]
	  }
	}
  }
  proc hsave {hashname filename} {
    upvar #0 $hashname hsavehashname
	if {[array exists hsavehashname]} {
	  set hsavefile [open $filename w]
	  foreach {key value} [array get hsavehashname] {
	    puts $hsavefile "${key}=${value}"
	  }
	  close $hsavefile
	}
  }
  proc hload {hashname filename} {
    upvar #0 $hashname hloadhashname
	hfree $hashname
	set hloadfile [open $filename]
	set linenum 0
	while {[gets $hloadfile line] >= 0} {
	  if {[regexp -- {([^\s]+)=(.*)$} $line wholematch item data]} {
	    set hloadhashname($item) $data
	  }
    }
	close $hloadfile
  }
  proc hfree {hashname} {
    upvar #0 $hashname hfreehashname
	if {[array exists hfreehashname]} {
      foreach key [array names hfreehashname] { 
	    unset hfreehashname($key) 
	  }
	}
  }
  proc hdel {hashname shoot} {
    upvar #0 $hashname hdelhashname
	if {[info exists hdelhashname($shoot)]} {
	  unset hdelhashname($shoot)
	}
  }
  proc hcopy {hashfrom hashto} {
	upvar #0 $hashfrom hashfromlocal $hashto hashtolocal
	array set hashtolocal [array get hashfromlocal]
  } 
  proc savehash {} {
    hsave "rssreader" "${::network}rssreader.hsh"
  }
  proc loadhash {type} {
    if {[file exists "${::network}rssreader.hsh"]} { 
	  rssreader::hload "rssreader" "${::network}rssreader.hsh" 
	}
    set count $rssreader::startupdelay
    foreach {key value} [array get ::rssreader] {
      if {[set idx [lsearch -glob [timers] "*$value*"]] != -1} {
	    killtimer [lindex [lindex [timers] $idx] 2]
      }
      timer $count $value
      incr count
    }
  }  
}
putlog "\002*Loaded* \017\00304\002RSS Reader\017 \002by \
Ford_Lawnmower irc.GeekShed.net #Script-Help .rss for help"


Répondre


Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
Tchat 100% gratuit -Discutez en toute liberté