Jump to content
chain

Cobi's RSS Poster Updated By NIGathan on Jul 02, 2008

Recommended Posts

  • Administrators
Posted

Creators Notes:

;==================================================
; RSS Poster
; by Cobi
;==================================================
; Commands:
; /rss Starts the rss poster (shortcut for /loadrsshist and /rsscfg)
; /addrss name host webfile channel count interval -- adds feed to rss.cfg (Implies /rsstimer)
; /showrss name host webfile channel count -- shows rss feed in channel (Implies /getrss and /parserss)
;
; ----- The following are internal commands and should only be used if messing around with the code. -----
; /loadrsshist Loads the history file so as not to post the same stuff over and over
; /closersshist Unloads the history file...
; /reloadrsshist Shortcut for /closersshist and /loadrsshist
; /rsscfg Loads rss.cfg file and parses it (Implies /rsstimer on every rss feed listed)
; /rsstimer name host webfile channel count interval starts a rss timer for the specified settings
; (Implies /showrss each interval)
; /getrss name host webfile file done -- downloades an rss feed then runs done when it is done (Implies /fixrss)
; /fixrss file -- fixes rss feed format. This is done automatically, and should only be done when debugging.
; /parserss file name channel count -- parses rss file and displays it in a channel
;
; Arguements:
; name = Name of feed (used for displaying purposes)
; host = Where to get the feed ( http://hostwebfile e.g. http://example.com/test.xml example.com is the host and /test.xml is the webfile.. )
; webfile = file on host
; file = local rss file
; channel = channel to show rss postings in
; count = how many rss posts to show at once
; interval = how often (in seconds) to show rss posts
; done = what to do when done downloading file
;
; Examples:
;
; Add a few rss feeds:
; /addrss mirc.net mirc.net /rss.php?type=news #rss 6 600
; /addrss SourceForge images.feedstermedia.com /feedcache/ostg/sourceforge/rss_sfnews.xml #rss 6 600
; /addrss NPR www.npr.org /rss/rss.php?topicId=1001 #rss 6 600
; /addrss Moreover p.moreover.com /page?o=rss002&c=Top%20stories&wiz=230176 #rss 6 600
; /addrss Copyright www.copyright.gov /rss.xml #rss 6 600
; /addrss podcastingnews www.podcastingnews.com /index.xml #rss 6 600
; /addrss Infoworld www.infoworld.com /rss/news.xml #rss 6 600
; /addrss BarkerJr.Net barkerjr.net /rss?c=2;f=5 #RSS 2 600
; /addrss Linux-Security www.linuxsecurity.com /static-content/linuxsecurity_hybrid.rdf #rss 6 600
; /addrss Planet-Source-Code www.planet-source-code.com /vb/channel/NewCode/channel.cdf #rss 6 600
; /addrss /. slashdot.org /rss/index.rss #rss 6 600
; /addrss ZDnet news.zdnet.com /2509-1_22-0-20.xml #rss 6 600
; /addrss IRC101 www.irc101.org /tier2.xml #rss 6 600
; /addrss MSDN msdn.microsoft.com /msdnmag/rss/recent.xml #rss 6 600
; /addrss Microsoft www.microsoft.com /communities/rss.aspx?&Title=Recent+Posts&CMTYSvcSource=MSCOMBlogPosts&CMTYRawShape=list&Params=%7eCMTYDataSvcParams%5e%7eArg+Name%3d'DateFormat'+Value%3d'MMM+d%2c+yyyy'%2f%5e%7e%2fCMTYDataSvcParams%5e&NumberOfItems=50 #rss 6 600
; /addrss &color;01,00W&color;00,01I&color;01,00R&color;00,01E&color;01,00D&color; wired.com /news/feeds/rss2/0,2610,,00.xml #rss 6 600
; /addrss RTCW ict.mcast.edu.mt /ictweb/davidmica/web/rss.xml #rss 6 600
; /addrss jaos software.jaos.org /cgi-bin/rss #rss 6 600
;
; Reload the config file:
; /rehashrss
;
; Edit the config file:
; /run notepad rss.cfg
;
; Load the config file and start posting news:
; /rss
;
; Contact:
; Cobi@winbots.org
; Cobi on Undernet (#phase, #rss, #game-trivia)
; Cobi on Winbots (#winbots)
; Cobi-Wan-Kenobi on Quakenet (#icechat)
; Cobi on SearchIRC Forums
; Winbots on UnrealIRCd Forums
; Cobi on mirc.net
;
; ChangeLog:
; v1.3 -- fixed memory bug
; v1.2 -- fixed the issue when the tags are not one word (

blah)
; v1.1 -- fixed rss.performance issue
; v1.0 -- Initial Release

My Notes:

Changed !list to !rsslist so it doesnt interfere with service bots.
Added an on TEXT for the following aliases incase your loading it through a bot:
/rehashrss = !rehashrss
/rss = !rss
/rssoff = !rssoff
Added a "!show " command. Put the title of the feed (the ones mentioned in !rsslist) in the parameter and all the news from that feed will be posted into the rss channel.
Added a !help command which displays the commands.
Added an on JOIN notice to users welcoming them with a tip to get them started.

 

on *:TEXT:!rss:#rss: { loadrsshist | rsscfg }
alias rss { loadrsshist | rsscfg }
alias closersshist { window -c @rss.hist | window -c @rss.performance }
alias reloadrsshist { closersshist | loadrsshist }
alias rsscfg {
  var %time = $ticks
  var %lcv2 = 0
  var %lcv = 1
  var %lines = $lines(rss.cfg)
  unset %list
  while (%lcv <= %lines) {
    if ($read(rss.cfg,%lcv)) {
      bunset &line
      bset -t &line 1 $read(rss.cfg,%lcv)
      if ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,<(.+)>(.+)</.+>)) {
        bunset &rss. $+ $regml(RSS,1)
        bset -t &rss. $+ $regml(RSS,1) 1 $regml(RSS,2)
      }
      elseif ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,</item>)) {
        rsstimer $bvar(&rss.feed,1,$bvar(&rss.feed,0)).text $bvar(&rss.host,1,$bvar(&rss.host,0)).text $bvar(&rss.file,1,$bvar(&rss.file,0)).text $bvar(&rss.channel,1,$bvar(&rss.channel,0)).text $bvar(&rss.feeds,1,$bvar(&rss.feeds,0)).text $bvar(&rss.interval,1,$bvar(&rss.interval,0)).text
        set %list %list $replacex($bvar(&rss.feed,1,$bvar(&rss.feed,0)).text,&amp;,&,&quot;,",&nbsp;,$chr(32),&color;,,&bold;,,&underline,)
        bunset &line &rss.*
        inc %Lcv2
      }
    }
    inc %lcv
  }
  if ($window(@rss.performance)) {
    aline @rss.performance ---
    aline @rss.performance Parsed %lcv Config Lines ( $+ %lcv2 rss entries) (rss.cfg) in $calc(($ticks - %time)/1000) Seconds
  }
}
alias rsstimer {
  ;$1 = feed name
  ;$2 = host
  ;$3 = file
  ;$4 = channel
  ;$5 = max
  ;$6 = interval
  showrss $1 $2 $3 $4 $5
  .timerrss. $+ $1 0 $6 showrss $1 $2 $3 $4 $5
}
alias showrss {
  ;$1 = feed name
  ;$2 = host
  ;$3 = file
  ;$4 = channel
  ;$5 = max
  set %time. $+ $1 $ticks
  .remove " $+ $1 $+ .rss $+ "
  getrss $1 $2 $3 $replace($1 $+ .rss,$chr(32),_) parserss $replace($1 $+ .rss,$chr(32),_) $1 $4 $5
}
alias getrss {
  ;$1 = feed name
  ;$2 = host
  ;$3 = file
  ;$4 = save
  ;$5- = done
  set %rss. $+ $1 $+ .file $3
  set %rss. $+ $1 $+ .host $2
  set %rss. $+ $1 $+ .save $4
  set %rss. $+ $1 $+ .done $5-
  sockopen rss. $+ $1 $2 80
}
on *:SOCKOPEN:rss.*:{
  sockwrite -tn $sockname GET % [ $+ [ $sockname $+ .file ] ] HTTP/1.1
  sockwrite -tn $sockname Host: % [ $+ [ $sockname $+ .host ] ]
  sockwrite -tn $sockname Accept: *.*, */*
  sockwrite -tn $sockname Connection: close
  sockwrite -tn $sockname $crlf
}
on *:sockclose:rss.*:{ fixrss % [ $+ [ $sockname $+ .save ] ] | % [ $+ [ $sockname $+ .done ] ] | unset % $+ $sockname $+ .* }
on *:sockread:rss.*:{
  if ($sockerr) { echo 1 -a ERROR | return }
  if (% [ $+ [ $sockname $+ .status ] ] != downloading) {
    var %1 | sockread %1 | tokenize 32 %1
    if ($1 == HTTP/1.1) { if ($2 != 200 && $2 != 206) { echo 1 -a ERROR } }
    elseif ($1 == Content-Range:) { set % [ $+ [ $sockname $+ .size ] ] $gettok($3,-1,47) }
    elseif ($1 == Content-Type:) { return }
    elseif (!$1) {
      set % [ $+ [ $sockname $+ .status ] ] Downloading
      return
    }
  }
  else {
    var %1 = % [ $+ [ $sockname $+ .save ] ]
    :sockread
    sockread &1
    if (!$sockbr) { return }
    bwrite $+(",%1,") -1 &1
    unset % [ $+ [ $sockname $+ .resume ] ]
  }
}

alias fixrss {
  ;$1 = rss file
  var %file = $1
  bread $1 0 $file($1).size &file
  breplace &file 10 32 13 32
  write -c $1
  var %lcv = 1
  var %size = $bvar(&file,0)
  while (%lcv <= %size) {
    parserss2 $1 $bvar(&file,%lcv,500).text
    inc %lcv 500
  }
}

alias parserss {
  ;$1 = rss file
  ;$2 = feed name
  ;$3 = channel
  ;$4 = max
  var %time = $ticks | var %lcv = 1 | var %lcv2 = 0 | var %lines = $file($1).size
  bread $1 0 %lines &file1
  while ((%lcv <= %lines) && (%lcv2 < $4)) { bunset &line | bcopy -c &line 1 &file1 %lcv $calc($iif($bfind(&file1,%lcv,$crlf),$bfind(&file1,%lcv,$crlf),$calc(%lines + 1)) - %lcv) | var %lcv = $calc($iif($bfind(&file1,%lcv,$crlf),$bfind(&file1,%lcv,$crlf),$calc(%lines + 1)) + 2)
    if (($bvar(&line,0) < 300) && ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,<(.+)>(.+)</.+>))) { if (($regml(RSS,1)) && ($regml(RSS,2))) { bunset &rss. $+ $gettok($regml(RSS,1),1,32) | bset -t &rss. $+ $gettok($regml(RSS,1),1,32) 1 $regml(RSS,2) } }
    elseif (($bvar(&line,0) < 300) && ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,</item>))) { checkalreadyrss $3 [[ $+ $2 $+ ]] $+ 10 $bvar(&rss.title,1,$bvar(&rss.title,0)).text  $+ (14 $bvar(&rss.link,1,$bvar(&rss.link,0)).text ) | inc %lcv2 | bunset &line &rss.* }
  }
  if ($window(@rss.performance)) {
    aline @rss.performance ---
    aline @rss.performance Parsed %lcv Bytes ( $+ %lcv2 rss entries) ( $+ $1 $+ ) in $calc(($ticks - %time)/1000) Seconds
  }
  if (%time. [ $+ [ $2 ] ]) { if ($window(@rss.performance)) {
aline @rss.performance Downloaded and Parsed %lcv Bytes ( $+ %lcv2 rss entries) ( $+ $1 $+ ) in $calc(($ticks - %time. [ $+ [ $2 ] ] )/1000) Seconds } | unset %time. $+ $2 } }

alias addrss {
  ;$1 = feed name
  ;$2 = host
  ;$3 = file
  ;$4 = channel
  ;$5 = max
  ;$6 = interval
  write rss.cfg <item>
  write rss.cfg $chr(32) $+ $chr(32) $+ <feed> $+ $1 $+ </feed>
  write rss.cfg $chr(32) $+ $chr(32) $+ <host> $+ $2 $+ </host>
  write rss.cfg $chr(32) $+ $chr(32) $+ <file> $+ $3 $+ </file>
  write rss.cfg $chr(32) $+ $chr(32) $+ <channel> $+ $4 $+ </channel>
  write rss.cfg $chr(32) $+ $chr(32) $+ <feeds> $+ $5 $+ </feeds>
  write rss.cfg $chr(32) $+ $chr(32) $+ <interval> $+ $6 $+ </interval>
  write rss.cfg </item>
  rsstimer $1 $2 $3 $4 $5 $6
}
on *:TEXT:!rehashrss:#rss: {
  timerrss.* off
  rsscfg
}
alias rehashrss {
  timerrss.* off
  rsscfg
}
on *:TEXT:!rssoff:#rss: {
  timerrss.* off
  closersshist
}
alias rssoff {
  timerrss.* off
  closersshist
}
on 100:TEXT:!addrss * * * * * *:{ addrss $2 $3 $4 $5 $6 $7 }
alias checkalreadyrss {
  if (sponsored isin $1-) { goto done }
  if ($file(rss.hist.tmp)) { .remove rss.hist.tmp }
  filter -ffc rss.hist rss.hist.tmp * $+ $strip($1-) $+ *
  if ($file(rss.hist.tmp)) { .remove rss.hist.tmp }
  if ($filtered > 0) { goto done }
  write rss.hist $strip($1-)
  ;  if (!$window(@rss.hist)) { echo 4 -a $nopath($script) $+ : ERROR: no history loaded... (try /loadrsshist) | halt }
  ;  aline @rss.hist $strip($1-)
  msg $replacex($1-,&amp;,&,&quot;,",&nbsp;,$chr(32),&color;,,&bold;,,&underline,)
  :done
}
alias loadrsshist {
  if (!$file(rss.hist).size) { write rss.hist History File }
  ;  .window -k0lh @rss.hist
  ;  .loadbuf @rss.hist rss.hist
  ;  .window -k0 @rss.performance
}
alias parserss2 {
  ;$1 = File
  ;$2- = XML data
  var %file = $1
  ;[Code by FiberOPtics] Thanks.. :P
  var %a, %b = $regsub($2-,/(?<=>)(?=s*<)/g,$lf,%a)
  tokenize 10 %a
  ;[/Code by FiberOPtics]
  var %lcv = 1
  while (%lcv <= $0) {
    bset -t &tmp $calc($bvar(&tmp,0) +1) $ [ $+ [ %lcv ] ] $+ $crlf
    inc %lcv
  }
  bwrite %file -1 $calc($bvar(&tmp,0) -2) &tmp
  bunset &tmp
}
on *:TEXT:!rsslist:#rss:{ msg $chan I syndicate the following: | msg $chan %list }
alias rsslist { msg $chan I syndicate the following: | msg $chan %list }

on *:TEXT:!show *:#rss: {
  if ($2) {
    %rssin = $replace($2-,$, )
    %rssinput = * $+ %rssin $+ *
    if (%rssin isin %list) {
      while $read(rss.hist, w, %rssinput) != $null {
        write -dw * $+ $2- $+ * rss.hist
      }
      rehashrss
    }
    else {
      msg # Sorry, I do not syndicate that feed.
    }
  }
  else {
    msg # What feed would you like to see?
    rsslist
  }
}

on *:JOIN:#RSS: {
  notice $nick Welcome to #RSS! I will be delivering the news here. Say "!help" to get started.
}

on *:TEXT:!help:#RSS: {
  msg # To see a list of feeds use "!rsslist"
  msg # To check for any updates use "!rehashrss"
  msg # To view a specific feed use "!show <feed>"
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...