# Part of Acrobat.
-import string, cPickle, random, urllib, sys, time, re, os, twitter, subprocess, datetime
+import string, cPickle, random, urllib, sys, time, re, os, twitter, subprocess, datetime, urlparse
from irclib import irc_lower, nm_to_n
# query karma
targ = ("http://www.xe.com/ucc/convert.cgi?From=%s&To=%s" % (args[0], args[1]))
try:
currencypage = urllib.urlopen(targ).read()
- match = re.search(r"(1 %s = [\d\.]+ %s)" % (args[0],args[1]),currencypage,re.MULTILINE)
+ match = re.search(r"(1 %s = [\d\.]+ %s)" % (args[0].upper(),args[1].upper()),currencypage,re.MULTILINE)
if match == None:
bot.automsg(public,nick,"Dear Chief Secretary, there is no money.")
else:
conn.privmsg(bot.channel,"%s remarks: %s" % (nick," ".join(cmd.split()[1:])))
else:
conn.privmsg(bot.channel,"(via %s) %s"%(nick," ".join(cmd.split()[1:])))
- bot.automsg(False,nick,"That URL was unique; I have posted it into IRC")
urldb[url]=UrlLog(url,nick)
### Deal with URLs spotted in channel
def twitterq(bot,cmd,nick,conn,public,twitapi):
if (not urlre.search(cmd)):
- bot.automsg(False,nick,"Please use 'twit' only with http URLs")
+ bot.automsg(False,nick,"Please use 'twit' only with http or https URLs")
return
urlstring = urlre.search(cmd).group(1)
tweetID = parts[-1]
try:
status = twitapi.GetStatus(tweetID)
- #print status, type(status), status=={}
if status == {}:
return "twitapi.GetStatus returned nothing :-("
if status.user == None and status.text == None:
tweeter_screen = "[not returned]" ; tweeter_name = "[not returned]"
tweetText = status.text.encode('UTF-8', 'replace')
tweetText = tweetText.replace('\n',' ')
+
+ for medium in status.media:
+ if "media_url_https" in medium:
+ link = medium["media_url_https"]
+ link = re.sub(r"/tweet_video_thumb/(\w+).jpg", r"/tweet_video/\1.mp4", link)
+ tweetText = tweetText.replace(medium["url"], link)
+ for url in status.urls:
+ toReplace = url.expanded_url
+
+ # remove tracking utm_ query parameters, for privacy and brevity
+ # code snippet from https://gist.github.com/lepture/5997883
+ rv = urlparse.urlparse(toReplace)
+ if rv.query:
+ query = re.sub(r'utm_\w+=[^&]+&?', '', rv.query)
+ toReplace = '%s://%s%s?%s' % (rv.scheme, rv.hostname, rv.path, query)
+
+ tweetText = tweetText.replace(url.url, toReplace)
+
+ tweetText = tweetText.replace(">",">")
+ tweetText = tweetText.replace("<","<")
+ tweetText = tweetText.replace("&","&")
+ tweetText = tweetText.encode('UTF-8', 'replace')
+
stringout = "tweet by %s (%s): %s" %(tweeter_screen,tweeter_name,tweetText)
except twitter.TwitterError:
terror = sys.exc_info()