Example #1
0
import time
import urllib
import urllib2

from basebot import BaseBot, startBot, parseArgs

GOOGLE = 'http://www.google.com/ig/calculator?hl=en&q='

class MathBot(BaseBot):
  def _act(self, connection, target, message):
    search = message.lower().strip()
    print search
    math_url = GOOGLE + urllib.quote(search)
    f = urllib2.urlopen(math_url)
    json_response = f.read()
    f.close()
    answer = json_response.split('rhs: "')[1].split('",')[0]
    connection.privmsg(target, answer)

if __name__ == '__main__':
    options, args = parseArgs()
    startBot(MathBot, options)
Example #2
0
from basebot import BaseBot, startBot, parseArgs

class ScoreBot(BaseBot):

  def _act(self, connection, target, message):
    person = message.split('++')
    connection.privmsg(target, answer)

if __name__ == '__main__':
    options, args = parseArgs()
    startBot(MyBot, options)
Example #3
0
        return 'date %s could not be parsed.  type eventbot: help if you need help.' % a_event_date
    events = self._remove_past_events(self._get_events())
    if len(events) > 0:
        for idx in range(len(events)):
            if events[idx][1] > a_event_date:
                events.insert(idx, (a_event_name, a_event_date, a_event_location))
                break
    else:
        events = [(a_event_name, a_event_date, a_event_location)]
    f = open(EVENT_FILE, 'w')
    for event in events:
        f.write('%s,%s,%s\n' %\
                    (event[NAME], event[DATE].strftime('%Y-%m-%d %H:%M'), event[LOCATION]))
    f.close()
    return 'event added'

  def _act(self, connection, target, message):
    message = message.lower().strip()
    action = message.split()[0]
    if action == 'help':
        answer = 'try eventbot:add event name, event date, event location OR eventbot: next'
    if action == 'add':
        answer = self.add_event(message[3:])
    if action == 'next':
        answer = self.get_next_event(message[4:])
    connection.privmsg(target, answer)

if __name__ == '__main__':
    options, args = parseArgs()
    startBot(EventBot, options)
Example #4
0
    url = 'http://www.google.com/ig/api?weather={0}'.format(params)
    f = urllib2.urlopen(url)
    try:
      xml = f.read()
      root = parseString(xml)
      forecast_information = root.getElementsByTagName(
          'forecast_information')[0]
      city = self._getData(forecast_information, 'city')
      current_conditions = root.getElementsByTagName('current_conditions')[0]
      temp_f = self._getData(current_conditions, 'temp_f')
      temp_c = self._getData(current_conditions, 'temp_c')
      humidity = self._getData(current_conditions, 'humidity')
      icon = self._getData(current_conditions, 'icon')
      rest, ext = os.path.splitext(icon)
      weather_type = os.path.basename(rest).replace('_', ' ')

      reply = 'the weather in {0} is currently {1}, {2} F ({3} C), {4}'.format(
          city, weather_type, temp_f, temp_c, humidity.lower())
      c.privmsg(target, reply)
    except KeyboardInterrupt:
      raise
    except:
      reply = "i'm having trouble with that one."
      c.privmsg(target, reply)
    finally:
      f.close()

if __name__ == '__main__':
  options, args = parseArgs()
  startBot(WeatherBot, options)
Example #5
0
from basebot import BaseBot, startBot, parseArgs
import urllib

class LocationBot(BaseBot):
  def _act(self, connection, target, msg):
    params = urllib.urlencode({'q' : msg})
    url = 'http://maps.google.com?{0}'.format(params)
    connection.privmsg(target, url)

if __name__ == '__main__':
  options, args = parseArgs()
  startBot(LocationBot, options)
Example #6
0
  def get_picture_url_from_flickr_result(self, result):
      return result.getSmall()

  def get_ascii_for_URL(self, url):
    params = urllib.urlencode({'webaddress' : url})
    ascii_url = '{0}?{1}'.format(ASCII_CONVERSION_URL, params)
    f = urllib2.urlopen(ascii_url)
    html = f.read()
    f.close()
    image = html.split('<font face="monospace, Courier" size = "1" color = "000000">')[1]
    image = image.split('</font>')[0]
    image = image.replace('&nbsp;', ' ')
    image = image.replace('<br>', '\n')
    return image

  def _act(self, connection, target, message):
    search = message.lower().strip()
    print search
    photo = flickr.photos_search(text=search, license='cc', per_page=1)[0]
    photo_url = self.get_picture_url_from_flickr_result(photo)
    print photo_url
    art = self.get_ascii_for_URL(photo_url)
    print art
    for line in art.split('\n'):
        connection.privmsg(target, line)
        time.sleep(.34)

if __name__ == '__main__':
    options, args = parseArgs()
    startBot(AsciiBot, options)