module documentation

Examples to demo the twitterclient code.

These demo functions should all run, with the following caveats:

  • You must have obtained API keys from Twitter, and installed them according to the instructions in the twitter HOWTO.
  • If you are on a slow network, some of the calls to the Twitter API may timeout.
  • If you are being rate limited while searching, you will receive a 420 error response.
  • Your terminal window / console must be able to display UTF-8 encoded characters.

For documentation about the Twitter APIs, see The Streaming APIs Overview and The REST APIs Overview.

For error codes see Twitter's Error Codes and Responses

Function corpusreader_demo Use :module:`TwitterCorpusReader` tp read a file of tweets, and print out
Function expand_tweetids_demo Given a file object containing a list of Tweet IDs, fetch the corresponding full Tweets, if available.
Function followtoscreen_demo Using the Streaming API, select just the tweets from a specified list of userIDs.
Function limit_by_time_demo Query the REST API for Tweets about NLTK since yesterday and send the output to terminal.
Function lookup_by_userid_demo Use the REST API to convert a userID to a screen name.
Function sampletoscreen_demo Sample from the Streaming API and send output to terminal.
Function search_demo Use the REST API to search for past tweets containing a given keyword.
Function setup Initialize global variables for the demos.
Function streamtofile_demo Write 20 tweets sampled from the public Streaming API to a file.
Function tracktoscreen_demo Track keywords from the public Streaming API and send output to terminal.
Function tweets_by_user_demo Use the REST API to search for past tweets by a given user.
Function twitterclass_demo Use the simplified Twitter class to write some tweets to a file.
Function verbose Decorator for demo functions
Function yesterday Get yesterday's datetime as a 5-tuple.
Constant ALL Select demo functions to run. E.g. replace the following line with "DEMOS = ALL[8:]" to execute only the final three demos.
Constant DEMOS Undocumented
Constant SPACER Undocumented
@verbose
def corpusreader_demo(): (source)

Use :module:`TwitterCorpusReader` tp read a file of tweets, and print out

  • some full tweets in JSON format;
  • some raw strings from the tweets (i.e., the value of the text field); and
  • the result of tokenising the raw strings.
@verbose
def expand_tweetids_demo(): (source)

Given a file object containing a list of Tweet IDs, fetch the corresponding full Tweets, if available.

@verbose
def followtoscreen_demo(limit=10): (source)

Using the Streaming API, select just the tweets from a specified list of userIDs.

This is will only give results in a reasonable time if the users in question produce a high volume of tweets, and may even so show some delay.

@verbose
def limit_by_time_demo(keywords='nltk'): (source)

Query the REST API for Tweets about NLTK since yesterday and send the output to terminal.

This example makes the assumption that there are sufficient Tweets since yesterday for the date to be an effective cut-off.

@verbose
def lookup_by_userid_demo(): (source)

Use the REST API to convert a userID to a screen name.

@verbose
def sampletoscreen_demo(limit=20): (source)

Sample from the Streaming API and send output to terminal.

@verbose
def search_demo(keywords='nltk'): (source)

Use the REST API to search for past tweets containing a given keyword.

def setup(): (source)

Initialize global variables for the demos.

@verbose
def streamtofile_demo(limit=20): (source)

Write 20 tweets sampled from the public Streaming API to a file.

@verbose
def tracktoscreen_demo(track='taylor swift', limit=10): (source)

Track keywords from the public Streaming API and send output to terminal.

@verbose
def tweets_by_user_demo(user='NLTK_org', count=200): (source)

Use the REST API to search for past tweets by a given user.

@verbose
def twitterclass_demo(): (source)

Use the simplified Twitter class to write some tweets to a file.

def verbose(func): (source)

Decorator for demo functions

def yesterday(): (source)

Get yesterday's datetime as a 5-tuple.

Select demo functions to run. E.g. replace the following line with "DEMOS = ALL[8:]" to execute only the final three demos.

Value
[twitterclass_demo,
 sampletoscreen_demo,
 tracktoscreen_demo,
 search_demo,
 tweets_by_user_demo,
 lookup_by_userid_demo,
 followtoscreen_demo,
...

Undocumented

Value
ALL[:]
SPACER: str = (source)

Undocumented

Value
'###################################'