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 |
Use :module:`TwitterCorpusReader` tp read a file of tweets, and print out |
Function | expand |
Given a file object containing a list of Tweet IDs, fetch the corresponding full Tweets, if available. |
Function | followtoscreen |
Using the Streaming API, select just the tweets from a specified list of userIDs. |
Function | limit |
Query the REST API for Tweets about NLTK since yesterday and send the output to terminal. |
Function | lookup |
Use the REST API to convert a userID to a screen name. |
Function | sampletoscreen |
Sample from the Streaming API and send output to terminal. |
Function | search |
Use the REST API to search for past tweets containing a given keyword. |
Function | setup |
Initialize global variables for the demos. |
Function | streamtofile |
Write 20 tweets sampled from the public Streaming API to a file. |
Function | tracktoscreen |
Track keywords from the public Streaming API and send output to terminal. |
Function | tweets |
Use the REST API to search for past tweets by a given user. |
Function | twitterclass |
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 |
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.
Given a file object containing a list of Tweet IDs, fetch the corresponding full Tweets, if available.
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.
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.
Select demo functions to run. E.g. replace the following line with "DEMOS = ALL[8:]" to execute only the final three demos.
Value |
|