RSS

 

Flux de données notamment utilisé pour la diffusion d'actualités sur Internet (voir http://fr.wikipedia.org/wiki/Really_Simple_Syndication pour plus de détails).

Pour recevoir automatiquement les 15 dernières pages modifiées du Wiki Tcl francophone, utilisez les URL indiquées en bas de page dans votre lecteur RSS.


Voici le script utilisé pour générer le flux RSS de ce wiki (version modifiée par Kroc et XG de http://wiki.tcl.tk/9140) :

Les modifications inclues :

  ###############################################################
  #
  # Configure this script using three simple variables!
  # - WikiFile contains the name of the Wikit database,
  #   typically called "wikit.tkd".
  # - WikiBaseUrl contains the URL of the Wiki.  This shouldn't
  #   have a page number (or a trailing /), as it's used toi
  #   generate the links for changed pages.
  # - MaxItems specifies the maximum number of changed pages to include
  #   in the RSS feed.
  #
  ###############################################################

  set WikiFile /home/wfr/cgi-bin/wikit.tkd
  set WikiBaseUrl http://wfr.tcl.tk
  set MaxItems 15

  ###############################################################
  #
  # The following constants are used to hide magic numbers
  #
  ###############################################################

  set SearchPageNum 2
  set RecentChangesPageNum 4

  ###############################################################
  #
  # The following procedures are used to generate the RSS feed.
  #
  ###############################################################

  # genHeader generates the header of the XML file.  Basically, it tells
  # what version of RSS is being used.
  #
  # No parameters are expected.

  proc genHeader {} {
    puts "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
    puts "<?xml-stylesheet type=\"text/xsl\" href=\"http://wfr.tcl.tk/wfr_rss.xsl\"?>"
    puts "<!DOCTYPE rss SYSTEM \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">"
    puts ""
    puts "<rss version=\"0.91\">"
    puts ""
  }

  # genChannel generates the channel information for the feed.  It says
  # what the name of the feed is (the same as the Wiki name), and where
  # the feed comes from (the Wiki URL).
  #
  # Two parameters are required:
  # - WikiName: the name of the Wiki
  # - Url: the URL of the Wiki

  proc genChannel {WikiName Url} {
    puts "  <channel>"
    puts "    <title>wfr.tcl.tk</title>"
    puts "    <link>$Url</link>"
    puts "    <description>$WikiName - derniers changements.</description>"
    puts ""
    puts "    <lastBuildDate>[clock format [clock second]]</lastBuildDate>"
    puts ""
    puts "    <language>fr</language>"
    puts ""
  }

  # genItem generates a single news item for the feed.
  # Each item is a different Wiki page.
  #
  # Four parameters are required:
  # - Title: the title of the Wiki page
  # - Time: the time (in "[clock seconds]" format) that the Wiki page
  #   was last modified
  # - Author: who last changed the Wiki page
  # - Url: the URL of the Wiki page
  #
  # You may not like the format that I've chosen to display the
  # news item name in.  It's pretty easy to change.
  # See the lines I've commented out for alternate formats.

  proc genItem {Title Time Author Url} {

    set Title [htmlQuote $Title]
    puts "  <item>"

    # This line causes the news item to look like:
    #   Wiki Page (June 19 11:40)
    puts "    <title>$Title ([clock format $Time -format "%d/%m/%y - %H:%M"])</title>"

    # Alternatively, you could use one of these:
    #   puts "    <title>$Title ($Author at [clock format $Time])</title>"
    # for format:
    #   Wiki Page (127.0.0.1 at Thu Jun 19 11:41:00 CST 2003)
    #
    # or:
    #   puts "    <title>$Title</title>"
    # for format:
    #   Wiki Page

    puts "    <link>$Url[clock format $Time -format "&amp;%Y%m%d%H%M%S"]</link>"
    puts "  </item>"
    puts ""
  }

  # genTail generates the tail of the XML file.
  # It just ends off the RSS element.
  #
  # No parameters are expected.

  proc genTail {} {

    puts "  </channel>"
    puts "</rss>"
  }

  # htmlQuote protects the tricky characters in a string

  proc htmlQuote {s} {
    string map { & &amp; < &lt; > &gt; } $s
  }

  ###############################################################
  #
  # The remainder of this file generates the RSS file.
  #
  ###############################################################

  package require Mk4tcl

  mk::file open WikiDB $WikiFile -nocommit -readonly
  mk::view layout WikiDB.pages {name page date:I who}

  # The Wikit implementation has the Wiki name as the name of page 0.
  set WikiName [mk::get WikiDB.pages!0 name]

  # Get a list of all page numbers, ordered from most recently changed
  # to least recently changed.
  set PageList [mk::select WikiDB.pages -rsort date]

  # Delete the "Search" and "Recent Changes" page from the page list
  set index [lsearch -exact $PageList $SearchPageNum]
  if { $index != -1 } {
    set PageList [lreplace $PageList $index $index]
  }
  set index [lsearch -exact $PageList $RecentChangesPageNum]
  if { $index != -1 } {
    set PageList [lreplace $PageList $index $index]
  }

  # Determine the number of pages to include in the RSS file.
  # At most, it can be $MaxItems, but if there aren't that many
  # pages, it's all the pages.
  set NumPages [llength $PageList]
  set NumItems [expr ( $NumPages < $MaxItems ) ? $NumPages : $MaxItems]

  # Generate the XML file

  genHeader

  genChannel $WikiName $WikiBaseUrl

  for {set i 0} {$i < $NumItems} {incr i} {

    set PageNum [lindex $PageList $i]

    lassign [mk::get WikiDB.pages!$PageNum name date who] name date who

    genItem $name $date $who $WikiBaseUrl/$PageNum

  }

  genTail

  mk::file close WikiDB

Flux RSS relatifs à Tcl/Tk :