#!/usr/local/bin/pyhton

import common
import feedparser
import imp
import sys

module_triggers = ['woot']


def Gather(keyword, msg = None, irc = None, channel = None):
  module_location = imp.find_module('common')
  module = imp.load_module('common', *module_location)
  if keyword == 'woot':
    result = WootLookup()
  common.DeliverMessage(result, irc, channel)


def WootLookup():
  """Get the latest woot.com listing
  
  Args:
    channel: string
    irc: IRCClient object

  Returns:
    None
  """
  feed = 'http://www.woot.com/blog/rss.aspx'
  data = feedparser.parse(feed)
  try:
    title = data['entries'][0]['title']
    link = data['entries'][0]['link']
  except IndexError:
    return 'Woot.com feed at http://www.woot.com/blog/rss.aspx is unavailable'
  return '%s, %s' % (title, link)


def main():
  try:
    keyword = sys.argv[1]
  except IndexError:
    sys.exit(1)

  if keyword in module_triggers:
    Gather(keyword)

if __name__ == '__main__':
  main()

