def func_del(self, args): length = len(args) if not length or ( length == 1 and (args[0].isdigit() or (args[0] and args[0][0] == "#" and args[0][1:].isdigit())) ): if not length: short_id = None statuses = self._api.get_user_timeline(screen_name=self._google_user.enabled_user, count=1) if statuses: id = statuses[0]["id"] else: return _("STATUS_NOT_FOUND") % "" elif args[0][0] == "#": short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = "#" + str(short_id) if short_id else str(id) try: response = self._api.destroy_status(id) except twitter.TwitterError, e: if "No status found" in e.message: return _("STATUS_NOT_FOUND") % id_str elif "You may not delete another user's status" in e.message: return _("DELETE_ANOTHER_USER_STATUS") else: return "" if response is None: return "" return _("STATUS_DELETED") % (id_str, response["text"])
def func_msg(self, args): length = len(args) if length == 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = '#' + str(short_id) if short_id else str(id) statuses = list() for __ in xrange(config.MAX_REPLY_STATUS): try: status = self._api.get_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: if statuses: break else: return _('STATUS_NOT_FOUND') % id_str else: return '' if status is None: break statuses.append(status) if 'in_reply_to_status_id' in status: id = status['in_reply_to_status_id'] else: break return _('STATUSES_CONVERSATION') + '\n\n' + utils.parse_statuses( statuses, reverse=False)
def func_reply(self, args): length = len(args) if not length or (length == 1 and (args[0][0].lower() == 'p' and args[0][1:].isdigit())): page = args[0][1:] if length else 1 statuses = self._api.get_mentions(page=int(page)) return _('MENTIONS') + _('PAGE') % str(page) + '\n\n' + utils.parse_statuses(statuses) elif length > 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())\ and ' '.join(args[1:])): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str message = u'@%s %s' % (status['user']['screen_name'], ' '.join(args[1:])) if len(message) > twitter.CHARACTER_LIMIT: return _('WORDS_COUNT_EXCEED') % (len(message), twitter.CHARACTER_LIMIT) try: self._api.post_update(message, id) except twitter.TwitterError, e: if 'Status is a duplicate' in e.message: return _('STATUS_DUPLICATE')
def func_msg(self, args): length = len(args) if length == 1 and (args[0].isdigit() or (args[0] and args[0][0] == "#" and args[0][1:].isdigit())): if args[0][0] == "#": short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = "#" + str(short_id) if short_id else str(id) statuses = list() for __ in xrange(config.MAX_REPLY_STATUS): try: status = self._api.get_status(id) except twitter.TwitterError, e: if "No status found" in e.message: if statuses: break else: return _("STATUS_NOT_FOUND") % id_str else: return "" if status is None: break statuses.append(status) if "in_reply_to_status_id" in status: id = status["in_reply_to_status_id"] else: break return _("STATUSES_CONVERSATION") + "\n\n" + utils.parse_statuses(statuses, reverse=False)
def func_fav(self, args): length = len(args) if not length or (length == 1 and (args[0][0].lower() == 'p' and args[0][1:].isdigit())): page = args[0][1:] if length else 1 statuses = self._api.get_favorites(page=int(page)) return _('FAVOURITES') + _('PAGE') % str( page) + '\n\n' + utils.parse_statuses(statuses) elif length == 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: self._api.create_favorite(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str else: return '' return _('FAVOURITED') % id_str
def func_ra(self, args): if len(args) > 1 and ( args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit()) and ' '.join(args[1:])): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str mention_users = [status['user']['screen_name']] if 'user_mentions' in status['entities']: for u in status['entities']['user_mentions']: name = u['screen_name'] if name != self._user['screen_name'] and name not in mention_users: mention_users.append(name) message = u'%s %s' % (' '.join(['@' + x for x in mention_users]), ' '.join(args[1:])) if len(message) > twitter.CHARACTER_LIMIT: return _('WORDS_COUNT_EXCEED') % (len(message), twitter.CHARACTER_LIMIT) try: self._api.post_update(message, id) except twitter.TwitterError, e: if 'Status is a duplicate' in e.message: return _('STATUS_DUPLICATE')
def func_fav(self, args): length = len(args) if not length or (length == 1 and (args[0][0].lower() == "p" and args[0][1:].isdigit())): page = args[0][1:] if length else 1 statuses = self._api.get_favorites(page=int(page)) return _("FAVOURITES") + _("PAGE") % str(page) + "\n\n" + utils.parse_statuses(statuses) elif length == 1 and (args[0].isdigit() or (args[0] and args[0][0] == "#" and args[0][1:].isdigit())): if args[0][0] == "#": short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = "#" + str(short_id) if short_id else str(id) try: self._api.create_favorite(id) except twitter.TwitterError, e: if "No status found" in e.message: return _("STATUS_NOT_FOUND") % id_str else: return "" return _("FAVOURITED") % id_str
def func_re(self, args): if len(args) == 1 and (args[0] and args[0].isdigit() or (args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: self._api.create_retweet(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str return _('SUCCESSFULLY_RETWEET') % id_str
def func_unfav(self, args): if len(args) == 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: self._api.destroy_favorite(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str return _('UNFAVOURITED') % id_str
def func_ra(self, args): if len(args) > 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit()) and ' '.join(args[1:])): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str else: return '' if status is None: return '' mention_users = [status['user']['screen_name']] if 'user_mentions' in status['entities']: for u in status['entities']['user_mentions']: name = u['screen_name'] if name != self._user[ 'screen_name'] and name not in mention_users: mention_users.append(name) message = u'%s %s' % (' '.join(['@' + x for x in mention_users ]), ' '.join(args[1:])) if len(message) > twitter.CHARACTER_LIMIT: return _('WORDS_COUNT_EXCEED') % (len(message), twitter.CHARACTER_LIMIT) try: self._api.post_update(message, id) except twitter.TwitterError, e: if 'Status is a duplicate' in e.message: return _('STATUS_DUPLICATE') else: return ''
def func_reply(self, args): length = len(args) if not length or (length == 1 and (args[0][0].lower() == 'p' and args[0][1:].isdigit())): page = args[0][1:] if length else 1 statuses = self._api.get_mentions(page=int(page)) return _('MENTIONS') + _('PAGE') % str( page) + '\n\n' + utils.parse_statuses(statuses) elif length > 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())\ and ' '.join(args[1:])): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str else: return '' if status is None: return '' message = u'@%s %s' % (status['user']['screen_name'], ' '.join( args[1:])) if len(message) > twitter.CHARACTER_LIMIT: return _('WORDS_COUNT_EXCEED') % (len(message), twitter.CHARACTER_LIMIT) try: self._api.post_update(message, id) except twitter.TwitterError, e: if 'Status is a duplicate' in e.message: return _('STATUS_DUPLICATE') else: return ''
def func_re(self, args): if len(args) == 1 and (args[0] and args[0].isdigit() or (args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: self._api.create_retweet(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str else: return '' return _('SUCCESSFULLY_RETWEET') % id_str
def func_ra(self, args): if len(args) > 1 and ( args[0].isdigit() or (args[0] and args[0][0] == "#" and args[0][1:].isdigit()) and " ".join(args[1:]) ): if args[0][0] == "#": short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = "#" + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if "No status found" in e.message: return _("STATUS_NOT_FOUND") % id_str else: return "" if status is None: return "" mention_users = [status["user"]["screen_name"]] if "user_mentions" in status["entities"]: for u in status["entities"]["user_mentions"]: name = u["screen_name"] if name != self._user["screen_name"] and name not in mention_users: mention_users.append(name) message = u"%s %s" % (" ".join(["@" + x for x in mention_users]), " ".join(args[1:])) if len(message) > twitter.CHARACTER_LIMIT: return _("WORDS_COUNT_EXCEED") % (len(message), twitter.CHARACTER_LIMIT) try: self._api.post_update(message, id) except twitter.TwitterError, e: if "Status is a duplicate" in e.message: return _("STATUS_DUPLICATE") else: return ""
def func_rt(self, args): length = len(args) if length >= 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str else: logging.error(e) return '' if status is None: return '' if length > 1: user_msg = ' '.join(args[1:]) + ' ' else: user_msg = '' message = u'%sRT @%s:%s' % ( user_msg, status['user']['screen_name'], status['text']) if len(message) > twitter.CHARACTER_LIMIT: message = message[:138] + '..' try: json = self._api.post_update(message, id) except twitter.TwitterError, e: if 'Status is a duplicate' in e.message: return _('STATUS_DUPLICATE') else: return ''
def func_rt(self, args): length = len(args) if length >= 1 and (args[0].isdigit() or (args[0] and args[0][0] == "#" and args[0][1:].isdigit())): if args[0][0] == "#": short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = "#" + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if "No status found" in e.message: return _("STATUS_NOT_FOUND") % id_str else: logging.error(e) return "" if status is None: return "" if length > 1: user_msg = " ".join(args[1:]) if ord(user_msg[-1]) < 128: user_msg += " " else: user_msg = "" message = u"%sRT @%s:%s" % (user_msg, status["user"]["screen_name"], status["text"]) if len(message) > twitter.CHARACTER_LIMIT: message = message[:138] + ".." try: json = self._api.post_update(message, id) except twitter.TwitterError, e: if "Status is a duplicate" in e.message: return _("STATUS_DUPLICATE") else: return ""
def func_unfav(self, args): if len(args) == 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: self._api.destroy_favorite(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str else: return '' return _('UNFAVOURITED') % id_str
def func_rt(self, args): length = len(args) if length >= 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit())): if args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str else: logging.error(e) return '' if length > 1: user_msg = ' '.join(args[1:]) else: user_msg = '' if user_msg and user_msg[-1].isalnum(): user_msg += ' ' message = u'%sRT @%s:%s' % (user_msg, status['user']['screen_name'], status['text']) if len(message) > twitter.CHARACTER_LIMIT: message = message[:138] + '..' try: json = self._api.post_update(message, id) except twitter.TwitterError, e: if 'Status is a duplicate' in e.message: return _('STATUS_DUPLICATE') else: logging.error('RT Error: %s' % e.message) return ''
def func_reply(self, args): length = len(args) if not length or (length == 1 and (args[0][0].lower() == "p" and args[0][1:].isdigit())): page = args[0][1:] if length else 1 statuses = self._api.get_mentions(page=int(page)) return _("MENTIONS") + _("PAGE") % str(page) + "\n\n" + utils.parse_statuses(statuses) elif length > 1 and ( args[0].isdigit() or (args[0] and args[0][0] == "#" and args[0][1:].isdigit()) and " ".join(args[1:]) ): if args[0][0] == "#": short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = int(args[0]) id_str = "#" + str(short_id) if short_id else str(id) try: status = self._api.get_status(id) except twitter.TwitterError, e: if "No status found" in e.message: return _("STATUS_NOT_FOUND") % id_str else: return "" if status is None: return "" message = u"@%s %s" % (status["user"]["screen_name"], " ".join(args[1:])) if len(message) > twitter.CHARACTER_LIMIT: return _("WORDS_COUNT_EXCEED") % (len(message), twitter.CHARACTER_LIMIT) try: self._api.post_update(message, id) except twitter.TwitterError, e: if "Status is a duplicate" in e.message: return _("STATUS_DUPLICATE") else: return ""
def func_del(self, args): length = len(args) if not length or (length == 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit()))): if not length: short_id = None id = self._user['status']['id'] elif args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: response = self._api.destroy_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str elif "You may not delete another user's status" in e.message: return _('DELETE_ANOTHER_USER_STATUS') return _('STATUS_DELETED') % (id_str, response['text'])
def func_del(self, args): length = len(args) if not length or ( length == 1 and (args[0].isdigit() or (args[0] and args[0][0] == '#' and args[0][1:].isdigit()))): if not length: short_id = None statuses = self._api.get_user_timeline( screen_name=self._google_user.enabled_user, count=1) if statuses: id = statuses[0]['id'] else: return _('STATUS_NOT_FOUND') % '' elif args[0][0] == '#': short_id = int(args[0][1:]) id = utils.restore_short_id(short_id, self._google_user.jid) elif int(args[0]) < config.MAX_SHORT_ID_LIST_NUM: short_id = int(args[0]) id = utils.restore_short_id(short_id, self._google_user.jid) else: short_id = None id = long(args[0]) id_str = '#' + str(short_id) if short_id else str(id) try: response = self._api.destroy_status(id) except twitter.TwitterError, e: if 'No status found' in e.message: return _('STATUS_NOT_FOUND') % id_str elif "You may not delete another user's status" in e.message: return _('DELETE_ANOTHER_USER_STATUS') else: return '' if response is None: return '' return _('STATUS_DELETED') % (id_str, response['text'])