Created
May 5, 2016 19:06
-
-
Save Seagor/3a100da48856072710d37e7d7a952b65 to your computer and use it in GitHub Desktop.
Stream and Filter Tweets using the Twitter Public Streaming API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
"exec" "twxec" "-e" "filter_stream()" "$0" "$@" | |
import oauth2 as oauth | |
from trickle import twitter as tw | |
{{docstring "Make sure you have registered an application with Twitter in order to obtain your credentials. Once you have them, start streaming tweets using one of the filtering parameteres below"}} | |
app_key = {{string Twitter_App_Key}} | |
app_secret = {{string Twitter_App_Secret}} | |
access_token = {{password Oauth_Access_Token}} | |
token_secret = {{password Oauth_Token_Secret}} | |
filter_param = {{string Filter_Parameter ["track", "locations"]}} | |
query = {{string Query}} | |
def filter_stream(): | |
token = oauth.Token(access_token, token_secret) | |
consumer = oauth.Consumer(app_key, app_secret) | |
_config = {filter_param: query} | |
with tw.FilterStream(token, consumer, _config) as stream: | |
for tweet in stream: | |
yield tweet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment