Created
September 7, 2016 03:23
-
-
Save neuromusic/043f7a14f3288bde9db96448ab24dcbe to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXX'\n", | |
"consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx'\n", | |
"\n", | |
"access_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'\n", | |
"access_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxx'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import tweepy\n", | |
"import json" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"auth = tweepy.OAuthHandler(consumer_key, consumer_secret)\n", | |
"auth.set_access_token(access_key, access_secret)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"api = tweepy.API(auth, wait_on_rate_limit=True,wait_on_rate_limit_notify=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"query = '#tomhankstop5'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Rate limit reached. Sleeping for: 784\n" | |
] | |
} | |
], | |
"source": [ | |
"max_tweets = 100000\n", | |
"for status in tweepy.Cursor(api.search, q=query).items(max_tweets):\n", | |
" if (status.retweeted==False) & (status.text.startswith('RT')==False):\n", | |
" \n", | |
" with open('tweets/{}.json'.format(status.id), 'w') as f:#, open('tomhankstop5-stream.txt','a') as txt:\n", | |
" json.dump(status._json,f)\n", | |
"# txt.write(status.text.encode('utf8'))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment