def twiCmdRetweetWithComment(self, params, r): """ # ttweet % retweet with your comment, differ from the offical retweet % format: .rt <tweet id> [your comment] """ pat = re.compile("(\d+)(?:(?:\s+)(.*))?$") m = pat.match( params ) if m is None: r.l("!bad argument") return tid, text = m.group(1), m.group(2) # collection origin author name... url = "https://api.twitter.com/1.1/statuses/show/%s.json" % tid succ, response = self.get( url, r ) if not succ: r.l( "!failed when fetching origin tweet" ) return data = json.loads( response.read() ) tweetObj = twitter_object.Tweet(data) author = tweetObj.owner if text is None: text = "RT @%s: %s" % (tweetObj.owner, tweetObj.text) else: text = "%s RT @%s: %s" % (text, tweetObj.owner, tweetObj.text) text = twig_command.cmdLengthCheck(None, text, r) url = mkURL("https://api.twitter.com/1.1/statuses/update.json", status=text, in_reply_to_status_id=tid) succ, response = self.post(url, r) if not succ: return r.l( "retweeted" )
def twiCmdReply(self, params, r): """ # ttweet % reply only to the author of a given tweet % * if you want to reply all users mentioned in a tweet, % please refer to '.help replyall' % format: .reply <id> <text> % e.g.: .reply 123456 I'm fine thank you, and you? """ pat = re.compile(r'^(\d+)(?:\s+)(.*)$') m = pat.match( params ) if m is None: r.l( "!bad argument") return tid, text = m.group(1), m.group(2) # at first we should find this tweet ... url = "https://api.twitter.com/1.1/statuses/show/%s.json" % tid succ, response = self.get( url, r ) if not succ: r.l( "!failed when fetching origin tweet" ) return user = json.loads( response.read() )["user"]["screen_name"] text = "@%s %s" % (user, text) text = twig_command.cmdLengthCheck( None, text, r) # now send text! url = mkURL( "https://api.twitter.com/1.1/statuses/update.json", status=text, in_reply_to_status_id=tid) succ, response = self.post( url, r ) if not succ: r.l("!failed when sending reply") return r.l( "replied to %s" % user )
def twiCmdReplyAll(self, params, r): """ # ttweet % reply to all users mentions in a given tweet % * if you want to reply only to the author of a tweet, % please refer to '.help reply' % format: .replyall <id> <text> % e.g.: .replyall 123456 I'm fine thank you, and you? """ pat = re.compile(r'^(\d+)(?:\s+)(.*)$') m = pat.match( params ) if m is None: r.l( "!bad argument") return tid, text = m.group(1), m.group(2) # at first we should find this tweet ... url = "https://api.twitter.com/1.1/statuses/show/%s.json" % tid succ, response = self.get( url, r ) if not succ: r.l( "!failed when fetching origin tweet" ) return data = json.loads( response.read() ) # metion list build: mention list should contain author # and all users mentioned except you author = data["user"]["screen_name"] # make use of "entities" to find users mentioned user_list = data["entities"]["user_mentions"] # let's filter out myself and transform it into a list # that contains screen name only user_list = filter ( lambda user: user["id_str"] != self.uid, user_list) user_list = map (lambda user: "******"+user["screen_name"], user_list ) user_list.append( "@" + author ) user_list = sorted( list( set( user_list ) ) ) text = "%s %s" % (' '.join(user_list), text) text = twig_command.cmdLengthCheck( None, text, r) # ok I'm ready to send url = mkURL( "https://api.twitter.com/1.1/statuses/update.json", status=text, in_reply_to_status_id=tid) succ, response = self.post( url, r ) if not succ: r.l("!failed when sending reply") return r.l( "replied to %s" % ' '.join( map(lambda t: t[1:], user_list) ) )
def twiCmdUpdate(self, params, r): """ # ttweet % send a new tweet % format: .update <text> % simply type in messages leading with anything but '.' % will send tweets as well, for messages leading with '.' % duplicating '.' will make it % e.g. "..net is good!" products ".net is good!" """ if params.isspace() or len(params) == 0: r.l("!blank text") return params = twig_command.cmdLengthCheck(None, params, r) url = mkURL("https://api.twitter.com/1.1/statuses/update.json", status=params) succ, response = self.post(url, r) if not succ: return r.l( "sent" )