Exemple #1
0
########################################################################## Section 13.13.2 snippets
# Authenticating
import tweepy

import keys

auth = tweepy.OAuthHandler(keys.consumer_key, keys.consumer_secret)

auth.set_access_token(keys.access_token, keys.access_token_secret)

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

# Creating a TweetListener
from tweetlistener import TweetListener

tweet_listener = TweetListener(api)

# Creating a Stream
tweet_stream = tweepy.Stream(auth=api.auth, listener=tweet_listener)

# Starting the TweetListeneret Stream
tweet_stream.filter(track=['Mars Rover'], is_async=True)

# Asynchronous vs. Synchronous Streams

# Other filter Method Parameters

# Twitter Restrictions Note

##########################################################################
# (C) Copyright 2019 by Deitel & Associates, Inc. and                    #
Exemple #2
0
senators_df.head()

# Configuring the MongoClient
from pymongo import MongoClient

atlas_client = MongoClient(keys.mongo_connection_string)

db = atlas_client.senators

# Setting up Tweet Stream
from tweetlistener import TweetListener

tweet_limit = 10000

twitter_stream = tweepy.Stream(api.auth, TweetListener(api, db, tweet_limit))

# Starting the Tweet Stream
twitter_stream.filter(track=senators_df.TwitterHandle.tolist(),
                      follow=senators_df.TwitterID.tolist())

# Class TweetListener

# Counting Tweets for Each Senator
db.tweets.create_index([('$**', 'text')])

tweet_counts = []

for senator in senators_df.TwitterHandle:
    tweet_counts.append(
        db.tweets.count_documents({"$text": {
Exemple #3
0
 def __init__(self):
     self.logger = MongoLogger('MiningBot', DB, debug=True)
     self.q = TweetQueue()
     self.listener = TweetListener(DB, self.q)
     self.saver = TweetSaver(self.q, DB)
     self.dbq = DBQueue()