The Twitter stream API lets you access a real-time stream of tweets. There are two ways to do this. The first is a sampling of random public tweets from the last seven days. To access this we can say barStream=bought.stream statuses/sample. Then we type stream.ontweet and then make a function to do something with that tweet.
We'll just print out the test, and a new line. This is just a random sampling of tweets. You could do control-C to cancel. For more speciific information, we can do bought.stream statuses/filter and then pass it some parameters.
There are several options here. First is to track and we can track via word. Let's try bots. That's not a super-popular one. If we tried something like win, we can see there are many more tweets for this one. You can also search for multiple words, and that will get you back tweets with either win or lose in them.
If you want both words in a tweet, just separate them by a space. You can think of spaces as the logical and, and commas as the logical or. One additional thing to know -- if you search for a word with punctuation, the punctuation is treated as attached to the word.
Searching win! Will only return tweets with this exact expression. Another cool thing we can do is filter by location, with the parameter locations. This takes two coordinates which represent a bounding box, with the first set of coordinates being the southwest corner. This location is New York City.
Finally, we can filter by the follow parameter, which lets us input the IDs of specific users. I know in advance that my own personal ID is here. If I send out a test tweet the stream receives it.