# Desc: XChat script the broadcasts the latest Iraqi civilian bodycount to
#       the current channel.
# Author: Andrew Perry
# Date: 070705
# License: GPL
# Credit to jboy of sdf for the original idea in a shell script
__module_name__ = "iqbc"
__module_version__ = "0.01"
__module_description__ = "Display Iraqi civilian bodycount"

import xchat

import os,sys, urllib

def chanmsg(msg):
	mychannel = xchat.get_info('channel')
	xchat.command("msg " + mychannel + " " + msg)

def iqbc(word, word_el, userdata):
    feed = urllib.urlopen("http://www.iraqbodycount.net/counters/headlines.js")
    # split this: ibc.headlines(22787, 25814,
    min, max = feed.readline().split("(")[1].split(",")[:2]
    min=int(min)
    max=int(max)
    chanmsg("|>> Reported civilian deaths caused by the war in Iraq: min %i - max: %i <<|" % (min, max) )
    return xchat.EAT_ALL

xchat.hook_command("iraq", iqbc, help="/iraq")
xchat.prnt("Iraqi bodycount info script loaded! Type '/iraq' for the latest numbers")
