X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/d5f58e6e509a562e021442f011ec6277a4a75561..ea5231b2fe0f40d87c9c7991b949c39c7cddd7e3:/twitter/ircbot.py diff --git a/twitter/ircbot.py b/twitter/ircbot.py index b4aff7c..873850d 100644 --- a/twitter/ircbot.py +++ b/twitter/ircbot.py @@ -34,6 +34,8 @@ oauth_token_file: """ +from __future__ import print_function + BOT_VERSION = "TwitterBot 1.4 (http://mike.verdone.ca/twitter)" CONSUMER_KEY = "XryIxN3J2ACaJs50EizfLQ" @@ -48,7 +50,10 @@ import sys import time from datetime import datetime, timedelta from email.utils import parsedate -from configparser import ConfigParser +try: + from configparser import ConfigParser +except ImportError: + from ConfigParser import ConfigParser from heapq import heappop, heappush import traceback import os @@ -77,7 +82,7 @@ def get_prefix(prefix_typ=None): try: import irclib -except: +except ImportError: raise ImportError( "This module requires python irclib available from " + "https://github.com/sixohsix/python-irclib/zipball/python-irclib3-0.4.8") @@ -86,7 +91,7 @@ OAUTH_FILE = os.environ.get('HOME', '') + os.sep + '.twitterbot_oauth' def debug(msg): # uncomment this for debug text stuff - # print >> sys.stderr, msg + # print(msg, file=sys.stdout) pass class SchedTask(object): @@ -176,7 +181,7 @@ class TwitterBot(object): # Skip updates beginning with @ # TODO This would be better if we only ignored messages # to people who are not on our following list. - if not text.startswith("@"): + if not text.startswith(b"@"): self.privmsg_channels( "%s %s%s%s %s" %( get_prefix(), @@ -223,12 +228,12 @@ class TwitterBot(object): def privmsg_channel(self, msg): return self.ircServer.privmsg( - self.config.get('irc', 'channel'), msg.encode('utf-8')) + self.config.get('irc', 'channel'), msg) def privmsg_channels(self, msg): return_response=True channels=self.config.get('irc','channel').split(',') - return self.ircServer.privmsg_many(channels, msg.encode('utf-8')) + return self.ircServer.privmsg_many(channels, msg) def follow(self, conn, evt, name): userNick = evt.source().split('!')[0]