Created
May 4, 2017 02:06
-
-
Save izotx/471e43dfcf27ec5646d0394919b1c7a5 to your computer and use it in GitHub Desktop.
Streaming Direct Messages from Twitter
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
from twitter import * | |
import os | |
import oauth | |
#Create a new Twitter app first: https://apps.twitter.com/app/new | |
APP_KEY,APP_SECRET = 'H3kQtN5PQgRiA0ocRCCjqjt2P', '51UaJFdEally81B7ZXjGHkDoDKTYy430yd1Cb0St5Hb1BVcDfE' | |
# OAUTH_TOKEN, OAUTH_TOKEN_SECRET = '149655407-TyUPMYjQ8VyLNY5p7jq0aMy8PjtFtd7zkIpDh3ZA', 'IUVpiDpoVmdO75UaHOTinAv5TOsAQmddttNENh9ofYuWO' | |
MY_TWITTER_CREDS = os.path.expanduser('my_app_credentials') | |
if not os.path.exists(MY_TWITTER_CREDS): | |
oauth_dance("crypto sentiments", APP_KEY, APP_SECRET, | |
MY_TWITTER_CREDS) | |
oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS) | |
auth = OAuth( | |
consumer_key=APP_KEY, | |
consumer_secret=APP_SECRET, | |
token=oauth_token, | |
token_secret=oauth_secret | |
) | |
twitter_userstream = TwitterStream(auth=auth, domain='userstream.twitter.com') | |
for msg in twitter_userstream.user(): | |
if 'direct_message' in msg: | |
print (msg['direct_message']['text']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment