X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=blobdiff_plain;f=commands.py;h=cea3a2a6d2d3ef627735184bcfdfab3cce978a9f;hp=8e3bfe6f336272374a82b0f67df0b81924dfebf2;hb=ed9407882a3ac5abd0d35434a7233450166a1e40;hpb=e14f3db5ce67b81dc19b28f71b0c88e109cba100 diff --git a/commands.py b/commands.py index 8e3bfe6..cea3a2a 100755 --- a/commands.py +++ b/commands.py @@ -501,8 +501,10 @@ def twitterq(bot,cmd,nick,conn,public,twitapi): stringout = getTweet(urlstring,twitapi) bot.automsg(public, nick, stringout) -def getTweet(urlstring,twitapi): +def getTweet(urlstring,twitapi,inclusion=False): unobfuscate_urls=True + expand_included_tweets=True + parts = string.split(urlstring,'/') tweetID = parts[-1] try: @@ -572,11 +574,16 @@ def getTweet(urlstring,twitapi): else: toReplace = '%s://%s%s' % (rv.scheme, rv.hostname, rv.path) # leave off the final '?' + if expand_included_tweets and not inclusion: + if rv.hostname == 'twitter.com' and re.search(r'status/\d+',rv.path): + quotedtweet = getTweet(toReplace, twitapi, inclusion=True) # inclusion parameter limits recursion. + tweetText += " Q{" + quotedtweet + "}" tweetText = tweetText.replace(url.url, toReplace) tweetText = tweetText.replace(">",">") tweetText = tweetText.replace("<","<") tweetText = tweetText.replace("&","&") + tweetText = tweetText.replace("\n"," ") stringout = "tweet by %s (%s): %s" %(tweeter_screen,tweeter_name,tweetText) except twitter.TwitterError: terror = sys.exc_info() @@ -584,4 +591,6 @@ def getTweet(urlstring,twitapi): except Exception: terror = sys.exc_info() stringout = "Error: %s" % terror[1].__str__() + if inclusion: + return stringout # don't want to double-encode it, so just pass it on for now and encode later return stringout.encode('UTF-8', 'replace')