Created
July 5, 2016 19:04
-
-
Save Seagor/1f0ef7aec9869bfd5eb62d9c78a2a9c6 to your computer and use it in GitHub Desktop.
Stream and filter Tweets using the Twitter Public Streaming API
This file contains hidden or 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}} | |
{{docstring "Use the dropdown menu below to select a filtering method"}} | |
filter_param = {{string Filter_Parameter ["track", "locations"]}} | |
{{docstring "Enter the parameters for your filter"}} | |
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