

We’ll configure the IP here to be localhost as all will run on the same machine and the port 9009. Now, we’ll make the main part which will make the app host socket connections that spark will connect with. def send_tweets_to_spark(http_resp, tcp_connection): After that, it sends every tweet to Spark Streaming instance (will be discussed later) through a TCP connection. Then, create a function that takes the response from the above one and extracts the tweets’ text from the whole tweets’ JSON object. Response = requests.get(query_url, auth=my_auth, stream=True) Now, we will create a new function called get_tweets that will call the Twitter API URL and return the response for a stream of tweets. My_auth = requests_oauthlib.OAuth1(CONSUMER_KEY, CONSUMER_SECRET,ACCESS_TOKEN, ACCESS_SECRET) Import the libraries that we’ll use as below: import socketĪnd add the variables that will be used in OAuth for connecting to Twitter as below: # Replace the values below with yours It should be easy to follow for any professional Python developer.įirst, let’s create a file called twitter_app.py and then we’ll add the code in it together as below.

TRENDING TWEET HOW TO
In this step, I’ll show you how to build a simple client that will get the tweets from Twitter API using Python and passes them to the Spark Streaming instance.
