def getAllTweets(self, since_id): tweets = [] for id in range(10): tweet = tweepy.Status() tweet.id = id tweet.user = User() tweet.user.name = "User-" + str(id) tweet.text = str(id) tweet.in_reply_to_status_id = None tweets.append(tweet) return tweets
async def on_twitter_event(request: Request): print("Received twitter event!") json_request = await request.json() print(json_request) # iterate over all mention events if "tweet_create_events" in json_request: tweet_create_events = json_request["tweet_create_events"] for tweet in tweet_create_events: tweet = tweepy.Status().parse(None, tweet) # Convert into Tweet object process_tweet(twitter_bot, tweet)
def get_all_comments(self, since_id): print("from mock getTweets") tweets = [] tweet = tweepy.Status() tweet.id = since_id tweet.user = User() tweet.user.name = "User-" + str(tweet.id) tweet.in_reply_to_status_id = since_id - 1 tweets.append(tweet) tweet = tweepy.Status() tweet.id = since_id + 1 tweet.user = User() tweet.user.name = "User-" + str(tweet.id) tweet.in_reply_to_status_id = since_id - 2 tweets.append(tweet) return tweets
def setUp(self): self.doc = { 'game': "127,fake_author,fake_player,1234,2018-07-17 00:28:59.979175," "000000000000000000000000000000000000000000,0,0,0" } self.fake_status = tweepy.Status() self.fake_status.__setattr__('id_str', '333') self.fake_status.__setattr__('text', "@bot_mention @opponent_mention 2") self.fake_status.__setattr__('in_reply_to_status_id', 1234) fake_player = tweepy.User() fake_player.__setattr__('screen_name', 'fake_player') self.fake_status.__setattr__('user', fake_player)
def setUp(self): fake_user = tweepy.User() fake_user.__setattr__('screen_name', 'fake_author') self.fake_status = tweepy.Status() self.fake_status.__setattr__('user', fake_user) self.fake_status.__setattr__('id_str', '12345678') self.fake_status.__setattr__('text', "some new game") self.fake_status.__setattr__('in_reply_to_status_id', None) entities = {} user_mentions = [] mentioned_user = {u'screen_name': 'mentioned_screenname'} user_mentions.append(mentioned_user) user_mentions.append(mentioned_user) entities[u'user_mentions'] = user_mentions self.fake_status.__setattr__('entities', entities)
def from_file(cls, filename, api): rc = cls(api) with open(filename, 'r') as f: data_from_file = json.load(f) cache = {} for key in data_from_file.keys(): cache[key] = [ tweepy.Status().parse(None, tweet) for tweet in data_from_file[key] ] rc.cache = cache return rc
def parse_statuses(self, items): self.statuses = tweepy.Status().parse_list(api=self.api, json_list=items) return self