Example #1
0
	def twiCmdListStatus(self, params, r):
		"""
			# tlist
			% show tweets in a given list
			% format: .ls <list id> [where]
			% use command '.where' for how to use '[where]'
		"""
		params = params.split()
		if len( params ) == 0:
			r.l("!bad argument")
			return
		if not params[0].isdigit():
			r.l("!bad argument")
			return
		extra = {}
		if len( params ) == 2:
			extra = tools.parseWhere( params[1] )
			if extra is None:
				r.l("!bad page argument")
				return
		assert extra is not None
		extra["list_id"] = params[0]
		url = mkURL( "https://api.twitter.com/1.1/lists/statuses.json", **extra )
		succ, response = self.get(url, r)	
		if not succ:
			return
		raw_data = response.read()
		tl = self._parseList( raw_data, twitter_object.Tweet )
		r.l( tl )
Example #2
0
	def twiCmdSearch(self, params, r):
		"""
			# ttweet
			% search tweets
			% format: .s "<query>" [where]
			% query can contain any characters including whitespace
			% use command '.where' for how to use '[where]'
			% e.g:  .s "bob and alice" <123456
		"""
		pat = re.compile( r'"(.*)"(\s+([<|>]\d+))?' )
		m = pat.match( params )
		if m is None:
			r.l( "!bad argument" )
			return
		q, _, where = m.groups()
		if where is None:
			where = ''
		query = tools.parseWhere( where )
		query["q"] = q
		url = mkURL( "https://api.twitter.com/1.1/search/tweets.json", **query)
		succ, response = self.get( url, r )
		if not succ:
			return
		data = json.loads( response.read() )["statuses"]
		tl = map( twitter_object.Tweet, data )
		tl.reverse()
		r.l( tl )
Example #3
0
	def twiCmdFavorite(self, params, r):
		"""
			# tfav
			% view tweets favorited by you or a specific user
			% format: .fav [user] [where]
			% both 'user' and 'where' are optional
			% if 'user' is not given, I will grab the favorate list of you.
			% use command '.where' for how to use '[where]'
		"""
		para_list = params.split()
		query = {}
		if len( para_list ) > 2:
			r.l("!bad argument")
			return
		if len( para_list ) == 0:
			# view favorite tweets of yourself
			query["user_id"] = self.uid
		elif len( para_list ) == 2:
			w = tools.parseWhere( para_list[1] )
			if w is None:
				r.l("!bad argument")
				return
			query.update(w)
			query["screen_name"] = para_list[0]
		else:
			# only 1 element in the list
			# which must be either [user] or [where]
			w = tools.parseWhere( para_list[0] )
			if w is None:
				# this is actually a user name
				query["screen_name"] = para_list[0]
			else:
				# this is a 'where' 
				query.update(w)
				query["user_id"] = self.uid
		url = mkURL( "https://api.twitter.com/1.1/favorites/list.json", **query )
		succ, response = self.get( url, r)
		if not succ:
			return
		raw_data = response.read()
		tl = self._parseList( raw_data, twitter_object.Tweet )
		r.l( tl )
Example #4
0
	def twiCmdHomeTimeline(self, params, r):
		"""
			# ttweet
			% show my home timeline
			% format: .ho [where]
			% use command '.where' for how to use '[where]'
		"""
		extra = tools.parseWhere( params )
		if extra is None:
			r.l("!bad page argument")
			return
		url = mkURL( "https://api.twitter.com/1.1/statuses/home_timeline.json", **extra )
		succ, response = self.get(url, r)	
		if not succ:
			return
		raw_data = response.read()
		tl = self._parseList( raw_data, twitter_object.Tweet )
		r.l( tl )
Example #5
0
	def twiCmdMyTweets(self, params, r):
		"""
			# ttweet
			% get my tweets
			% format: .me [where]
			% use command '.where' for how to use '[where]'
		"""
		extra = tools.parseWhere( params )
		if extra is None:
			r.l( "!bad argument" )
			return
		extra["user_id"] = self.uid
		url = mkURL( "https://api.twitter.com/1.1/statuses/user_timeline.json", **extra )
		succ, response = self.get( url, r )
		if not succ:
			return
		raw_data = response.read()
		tl = self._parseList( raw_data, twitter_object.Tweet )
		r.l( tl )
Example #6
0
	def twiCmdDirectMessageSent(self, params, r):
		"""
			# tdm
			% view sent direct messages (outbox)
			% format: .dout [where]
			% use command '.where' for how to use '[where]'

		"""
		extra = tools.parseWhere( params )
		if extra is None:
			r.l("!bad page argument")
			return
		url = mkURL ( "https://api.twitter.com/1.1/direct_messages/sent.json", **extra )
		succ, response = self.get( url, r )	
		if not succ:
			return
		raw_data = response.read()
		tl = self._parseList( raw_data, twitter_object.DirectMessage )
		r.l( tl )
Example #7
0
	def twiCmdUserTimeline(self, params, r):
		"""
			# ttweet
			% view timeline of a given user
			% format: .tl [user] [where] 
			% both 'user' and 'where' are optional
			% 'user' is you by default
			% use command '.where' for how to use '[where]'
		"""
		para_list = params.split()
		query = {}
		if len( para_list ) > 2:
			r.l( "!bad argument" )
		if len( para_list ) == 0:
			# identical to '.me'
			self.twiCmdMyTweets( params, r )
			return
		if len( para_list ) == 1:
			if para_list[0][0] in '<>':
				# identical to '.me'
				self.twiCmdMyTweets( params, r)
				return
			else:
				# is a user
				query["screen_name"] = para_list[0]
		else:
			# has both user and 'where'
			extra = tools.parseWhere( para_list[1] )
			if extra is None:
				r.l ( "!bad argument" )
				return
			query.update( extra )
			query["screen_name"] = para_list[0]
		# query is ready
		url = mkURL("https://api.twitter.com/1.1/statuses/user_timeline.json", **query)
		succ, response = self.get( url, r )
		if not succ:
			return
		raw_data = response.read()
		tl = self._parseList( raw_data, twitter_object.Tweet )
		r.l( tl )
Example #8
0
	def twiCmdMention(self, params, r):
		"""
			# ttweet
			% show my mentions timeline
			% * if you are seeking help for how to reply others,
			%   please refer to '.help reply'
			% format: .mention [where]
			% use command '.where' for how to use '[where]'
		"""
		extra = tools.parseWhere( params )
		if extra is None:
			# there is another form of reply, jump to it.
			self.twiCmdReply( params, r )
			return

		url = mkURL( "https://api.twitter.com/1.1/statuses/mentions_timeline.json", **extra )
		succ, response = self.get(url, r)	
		if not succ:
			return
		raw_data = response.read()
		tl = self._parseList( raw_data, twitter_object.Tweet )
		r.l( tl )