chiark / gitweb /
Patch from adam to expand quoted tweet (1 level only)
authorMatthew Vernon <matthewv@chiark.greenend.org.uk>
Tue, 12 Jul 2016 21:06:08 +0000 (22:06 +0100)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Tue, 12 Jul 2016 21:06:08 +0000 (22:06 +0100)
commands.py

index 538de0960741ff2dd5f3c503055820cf7a5365f4..cea3a2a6d2d3ef627735184bcfdfab3cce978a9f 100755 (executable)
@@ -501,8 +501,10 @@ def twitterq(bot,cmd,nick,conn,public,twitapi):
     stringout = getTweet(urlstring,twitapi)
     bot.automsg(public, nick, stringout)
   
     stringout = getTweet(urlstring,twitapi)
     bot.automsg(public, nick, stringout)
   
-def getTweet(urlstring,twitapi):
+def getTweet(urlstring,twitapi,inclusion=False):
   unobfuscate_urls=True
   unobfuscate_urls=True
+  expand_included_tweets=True
+
   parts = string.split(urlstring,'/')
   tweetID = parts[-1]
   try:
   parts = string.split(urlstring,'/')
   tweetID = parts[-1]
   try:
@@ -572,6 +574,10 @@ def getTweet(urlstring,twitapi):
             else:
                 toReplace = '%s://%s%s' % (rv.scheme, rv.hostname, rv.path) # leave off the final '?'
 
             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("&gt;",">")
         tweetText = tweetText.replace(url.url, toReplace)
 
     tweetText = tweetText.replace("&gt;",">")
@@ -585,4 +591,6 @@ def getTweet(urlstring,twitapi):
   except Exception:
     terror = sys.exc_info()
     stringout = "Error: %s" % terror[1].__str__()
   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')
   return stringout.encode('UTF-8', 'replace')