示例#1
0
 def getTrends(self, woid ):
     try:
         js=self.twApi.trends_place(woid)
     except tweepy.RateLimitError as e:
         raise TwitterRateLimitExceed()
     except tweepy.TweepError as e:
         raise TwitterError(msg=e.message)
     return js
示例#2
0
 def unFollowByScreenName(self, screenName):
     try:
         status = self.twApi.destroy_friendship(screen_name=screenName)
     except tweepy.RateLimitError:
         raise TwitterRateLimitExceed()
     except tweepy.TweepError as e:
         raise TwitterError(msg=e.message)
     return status
示例#3
0
 def followUserByUserId(self, userId):
     try:
         status = self.twApi.create_friendship(user_id=userId)
     except tweepy.RateLimitError:
         raise TwitterRateLimitExceed()
     except tweepy.TweepError as e:
         raise TwitterError(msg=e.message)
     return status
示例#4
0
 def postTweet(self, tweetStr):
     try:
         status = self.twApi.update_status(status=tweetStr)
     except tweepy.RateLimitError:
         raise TwitterRateLimitExceed()
     except tweepy.TweepError as e:
         raise TwitterError(msg=e.message)
     return status
示例#5
0
 def replyTweet(self, text, user, tweetId):
     try:
         m = "@%s " %(user)+text
         self.twApi.update_status(m, in_reply_to_status_id=tweetId)
     except tweepy.RateLimitError as e:
         raise TwitterRateLimitExceed()
     except tweepy.TweepError as e:
         raise TwitterError(msg=e.message)
     return m
示例#6
0
 def __init__(self, consumer_key, consumer_secret, access_token, access_token_secret):
     try:
         auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
         auth.set_access_token(access_token, access_token_secret)
         self.twApi= tweepy.API(auth, wait_on_rate_limit=True)
     except tweepy.RateLimitError as e:
         raise TwitterRateLimitExceed()
     except tweepy.TweepError as e:
         raise TwitterError(msg=e.message)
示例#7
0
    def search(self, query, maxTweets, sinceId=0):
        log.info("Gonna to do search, query: "+str(query))

        try:
            if sinceId==0:
                searched_tweets = [status for status in tweepy.Cursor(self.twApi.search, q=query,
                                                                      ).items(maxTweets)]
            else:
                searched_tweets = [status for status in tweepy.Cursor(self.twApi.search, q=query,
                                             since_id=sinceId).items(maxTweets)]

        except tweepy.RateLimitError as e:
            log.info("Rate limit error")
            raise TwitterRateLimitExceed()
        except tweepy.TweepError as e:
            log.info("Tweep error")
            raise TwitterError(msg=e.message)
        return searched_tweets