]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/ircbot.py
Fix oauth_dance function.
[z_archive/twitter.git] / twitter / ircbot.py
index b4aff7c338c46bcd8113124204ba4a6053339d3c..873850d8715e3805e711e8877d926897de660eb9 100644 (file)
@@ -34,6 +34,8 @@ oauth_token_file: <oauth_token_filename>
 
 """
 
+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]