Show the entry count from the LANparty.de Mitfahrzentrale

# lanparty_mfz.tcl
#
# Copyright (c) 2003 Jochen "Y0Gi" Kupperschmidt <http://homework.nwsnet.de/>
# Version: 14-Sep-2003
# Released under the terms of the MIT License.
#
# Fetches the LANparty.de MFZ entry count of your party.
# Just type '!mfz' in a channel the bot is in.

package require http

# URL of the mfz script. Replace XXXXX with your party id.
set mfz_url "http://www.lanparty.de/events/mfz/?id=XXXXX"

bind pub - !mfz lanparty_mfz

proc lanparty_mfz {nick uhost hand chan text} {
    global mfz_url

    # Read XML data as string through HTTP.
    set token [http::geturl $mfz_url]
    set data [http::data $token]

    # Count occurences of the <item> element.
    set num [regexp -all -nocase -- "<item>" $data]

    # Polish the output.
    if {$num < 1} {
        set entries "kein Eintrag"
    } elseif {$num == 1} {
        set entries "1 Eintrag"
    } else {
        set entries "$num Einträge"
    }
    puthelp "PRIVMSG $chan :$entries in der Mitfahrzentrale"
    return 0
}

putlog "lanparty_mfz.tcl loaded."