More fixes.

This commit is contained in:
spline 2012-10-27 14:54:17 -04:00
parent b8ef2b72e7
commit f40a232155

View File

@ -255,6 +255,7 @@ class Tweety(callbacks.Plugin):
haveAuthKeys = self._checkCredentials() haveAuthKeys = self._checkCredentials()
def _checkCredentials(self): def _checkCredentials(self):
"""Check for all 4 requires keys on Twitter auth."""
failTest = False failTest = False
for checkKey in ('consumerKey', 'consumerSecret', 'accessKey', 'accessSecret'): for checkKey in ('consumerKey', 'consumerSecret', 'accessKey', 'accessSecret'):
try: try:
@ -264,10 +265,10 @@ class Tweety(callbacks.Plugin):
break break
if failTest: if failTest:
self.log.info('Failed') self.log.error('Failed getting keys')
return False return False
else: else:
self.log.info('Passed') self.log.info('Passed getting keys')
return True return True
#def re_encode(input_string, decoder = 'utf-8', encoder = 'utf=8'): #def re_encode(input_string, decoder = 'utf-8', encoder = 'utf=8'):
@ -425,6 +426,7 @@ class Tweety(callbacks.Plugin):
irc.reply(("Something broke while looking up: '%s'") % (lookup)) irc.reply(("Something broke while looking up: '%s'") % (lookup))
woeidlookup = wrap(woeidlookup, ['text']) woeidlookup = wrap(woeidlookup, ['text'])
# RATELIMITING # RATELIMITING
# https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status # https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status
@ -497,17 +499,17 @@ class Tweety(callbacks.Plugin):
try: try:
location = data[0]['locations'][0]['name'] location = data[0]['locations'][0]['name']
except: except:
irc.reply("ERROR: Location not found for: %s" % optwoeid) # error also throws 404. irc.reply("ERROR: Cannot load trends: {0}".format(data)) # error also throws 404.
self.log.info('ERROR: Location not found for: %s' % optwoeid) self.log.info("Trends error data: {0}".format(data))
self.log.info('DATA: %s' % data)
return return
ttrends = string.join([trend['name'] for trend in data[0]['trends']], " | ") ttrends = string.join([trend['name'].encode('utf-8') for trend in data[0]['trends']], " | ")
retvalue = "Top 10 Twitter Trends in {0} :: {1}".format(ircutils.bold(location), ttrends) retvalue = "Top 10 Twitter Trends in {0} :: {1}".format(ircutils.bold(location), ttrends)
irc.reply(retvalue) irc.reply(retvalue)
trends = wrap(trends, [optional('text')]) trends = wrap(trends, [optional('text')])
# https://dev.twitter.com/docs/api/1.1/get/search/tweets # https://dev.twitter.com/docs/api/1.1/get/search/tweets
def tsearch(self, irc, msg, args, optlist, optterm): def tsearch(self, irc, msg, args, optlist, optterm):
@ -629,6 +631,14 @@ class Tweety(callbacks.Plugin):
except: except:
irc.reply("Failed to get user's timeline. Twitter broken?") irc.reply("Failed to get user's timeline. Twitter broken?")
return return
# final sanity check for json
try:
data = json.loads(data)
except:
irc.reply("ERROR: Failed to parse data from Twitter: {0}".format(data))
self.log.error(str(data))
return
# process the data. # process the data.
if args['id']: # If --id was given for a single tweet. if args['id']: # If --id was given for a single tweet.