def on_status(self, status): # aca levantar el status y encolarlo para el worker. print(status.id, ' ', status.text) new_user, _ = User.get_or_create(user_id=status.user.id) try: tweet = Tweet.select().where(Tweet.status_id == status.id).get() except Tweet.DoesNotExist: tweet = None if tweet is not None: print("stream: already saved", status.user.id, status.id_str) else: new_twit = Tweet.create(user=new_user, status_id=status.id, text=status.text, json=jsonpickle.encode(status._json, unpicklable=False)) new_twit.save() print("stream: new ", status.user.id) return True
# Tell the Cursor method that we want to use the Search API (api.search) # Also tell Cursor our query, and the maximum number of tweets to return for status in Cursor(api.search, q=searchQuery).items(maxTweets): new_user, _ = User.get_or_create(user_id=status.user.id) try: tweet = Tweet.select().where(Tweet.status_id == status.id).get() except Tweet.DoesNotExist: tweet = None if tweet is not None: print("search: already saved", status.user.id, status.id_str) else: new_twit = Tweet.create(user=new_user, status_id=status.id, text=status.text, json=jsonpickle.encode(status._json, unpicklable=False)) new_twit.save() print("search: new ", status.user.id) # Write the JSON format to the text file, and add one to the number of tweets we've collected tweetCount += 1 # Display how many tweets we have collected print("Downloaded {0} tweets".format(tweetCount)) exit(0) # http://www.dealingdata.net/2016/07/23/PoGo-Series-Tweepy/ print("Starting stream to db") stream = Stream(auth, l) # stream.filter(track=['downtime99999'])