human
Give me a the Python code you requested given the following:
2. Tweet Extraction
We use the twython library for the tweet extraction. Twython is an actively maintained, pure Python wrapper for the Twitter API. It supports both normal and streaming Twitter APIs.
The primary task is to obtain the keys and tokens required to access the API and then access the functions in the wrappers.
The scripts below have two configurable parameters:
1. The query_word variable needs to be initialized with the keywords we are looking for on the twitter feed
2. The max_tweets variable is the number of tweets we plan to extract for the keywords mentioned above
If query_word is initialized to multiple words, the code will retrieve set of tweets that consists of all the words.
2.1. Streaming API
The streaming API is used to access all the current tweets. It returns approximately 1% of the tweets i.e. 60 tweets per second assuming a maximum of 6000 users tweet every second. There is no rate limit to the Streaming API.
The hyperlink has details related to the Twitter Streaming API limit:
1. URL 1
2. URL 2
assistant
#Here is the Python code you requested.
#import libraries
from twython import TwythonStreamer
from twython import Twython, TwythonError
import time
import sys
import os

#Configurable parameters
query_word="access-role"
max_tweets=5

searched_tweets_strm=[]

class MyStreamer(TwythonStreamer):
    def on_success(self, data):
        if len(searched_tweets_strm)<max_tweets:
            if 'text' in data:
                #print data['text'].encode('utf-8')
                searched_tweets_strm.append(data['text'].encode('utf-8'))
            else:
                print ("No tweets found")
                self.disconnect()
        else: 
            print ("Max tweets extracted")
            sys.exit()

    def on_error(self, status_code, data):
        print (status_code, data)
        print ("Exception raised, waiting 15 minutes")
        time.sleep(15*60)

# Requires Authentication as of Twitter API v1.1
stream = MyStreamer(APP_KEY, APP_SECRET,
                    OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

stream.statuses.filter(track=query_word)

print (searched_tweets_strm)