chiark / gitweb /
new trout from adam (http://www.bbc.co.uk/news/uk-england-bristol-41167296)
[irc.git] / commands.py
index 538de0960741ff2dd5f3c503055820cf7a5365f4..86d0d2331acd6c8374219c9c740c82b40fe5e2c3 100755 (executable)
@@ -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:
@@ -519,7 +521,7 @@ def getTweet(urlstring,twitapi):
     else:
         tweeter_screen = "[not returned]" ; tweeter_name = "[not returned]"
         tweeter_name = tweeter_name + " RTing " + status.user.name #.encode('UTF-8', 'replace')
-    tweetText = status.text
+    tweetText = status.full_text
     if status.media:
         replacements = defaultdict( list )
         for medium in status.media:
@@ -527,7 +529,7 @@ def getTweet(urlstring,twitapi):
 
         for k,v in replacements.items():
 
-            v = [re.sub(r"/tweet_video_thumb/(\w+).jpg", r"/tweet_video/\1.mp4", link) for link in v]
+            v = [re.sub(r"/tweet_video_thumb/([\w\-]+).jpg", r"/tweet_video/\1.mp4", link) for link in v]
             if len(v) > 1:
                 replacementstring = "[" +  " ; ".join(v) +"]"
             else:
@@ -572,6 +574,10 @@ 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(">",">")
@@ -585,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')