mirror of
https://github.com/balkian/gists.git
synced 2024-11-25 10:42:28 +00:00
5975d417b7
git-subtree-dir: repos/e6890355c392e5a99c3b65b1a4030817 git-subtree-mainline:f5a7820975
git-subtree-split:04ad72df58
163 lines
5.3 KiB
Plaintext
163 lines
5.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Install a pip package in the current Jupyter kernel.\n",
|
|
"import sys\n",
|
|
"import site\n",
|
|
"usersite = site.getusersitepackages()\n",
|
|
"if usersite not in sys.path:\n",
|
|
" sys.path.append(usersite)\n",
|
|
"!{sys.executable} -m pip install --user bitter\n",
|
|
"import os\n",
|
|
"import bitter\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Getting twitter credentials\n",
|
|
"\n",
|
|
"* Go to https://apps.twitter.com/\n",
|
|
"* Sign in with your Twitter credentials\n",
|
|
"* Create a new application.\n",
|
|
"* Go to \"Keys and Access Tokens\"\n",
|
|
"* Copy:\n",
|
|
" * Consumer Key (API Key)\n",
|
|
" * Consumer Secret (API Secret)\n",
|
|
" * Access Token\n",
|
|
" * Access Token Secret\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'contributors_enabled': False,\n",
|
|
" 'created_at': 'Tue Mar 04 07:54:11 +0000 2008',\n",
|
|
" 'default_profile': True,\n",
|
|
" 'default_profile_image': True,\n",
|
|
" 'description': '',\n",
|
|
" 'entities': {'description': {'urls': []}},\n",
|
|
" 'favourites_count': 0,\n",
|
|
" 'follow_request_sent': False,\n",
|
|
" 'followers_count': 8,\n",
|
|
" 'following': False,\n",
|
|
" 'friends_count': 0,\n",
|
|
" 'geo_enabled': False,\n",
|
|
" 'has_extended_profile': False,\n",
|
|
" 'id': 14076913,\n",
|
|
" 'id_str': '14076913',\n",
|
|
" 'is_translation_enabled': False,\n",
|
|
" 'is_translator': False,\n",
|
|
" 'lang': 'en',\n",
|
|
" 'listed_count': 1,\n",
|
|
" 'location': \" 19° 1'3.56N, 72°51'22.24E\",\n",
|
|
" 'name': 'torvalds',\n",
|
|
" 'notifications': False,\n",
|
|
" 'profile_background_color': 'C0DEED',\n",
|
|
" 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png',\n",
|
|
" 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png',\n",
|
|
" 'profile_background_tile': False,\n",
|
|
" 'profile_image_url': 'http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png',\n",
|
|
" 'profile_image_url_https': 'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png',\n",
|
|
" 'profile_link_color': '1DA1F2',\n",
|
|
" 'profile_location': None,\n",
|
|
" 'profile_sidebar_border_color': 'C0DEED',\n",
|
|
" 'profile_sidebar_fill_color': 'DDEEF6',\n",
|
|
" 'profile_text_color': '333333',\n",
|
|
" 'profile_use_background_image': True,\n",
|
|
" 'protected': False,\n",
|
|
" 'screen_name': 'torvalds',\n",
|
|
" 'status': {'contributors': None,\n",
|
|
" 'coordinates': None,\n",
|
|
" 'created_at': 'Tue Nov 03 20:52:32 +0000 2009',\n",
|
|
" 'entities': {'hashtags': [], 'symbols': [], 'urls': [], 'user_mentions': []},\n",
|
|
" 'favorite_count': 1,\n",
|
|
" 'favorited': False,\n",
|
|
" 'geo': None,\n",
|
|
" 'id': 5401305338,\n",
|
|
" 'id_str': '5401305338',\n",
|
|
" 'in_reply_to_screen_name': None,\n",
|
|
" 'in_reply_to_status_id': None,\n",
|
|
" 'in_reply_to_status_id_str': None,\n",
|
|
" 'in_reply_to_user_id': None,\n",
|
|
" 'in_reply_to_user_id_str': None,\n",
|
|
" 'is_quote_status': False,\n",
|
|
" 'lang': 'en',\n",
|
|
" 'place': None,\n",
|
|
" 'retweet_count': 2,\n",
|
|
" 'retweeted': False,\n",
|
|
" 'source': '<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>',\n",
|
|
" 'text': 'is twittering from php using curl',\n",
|
|
" 'truncated': False},\n",
|
|
" 'statuses_count': 8,\n",
|
|
" 'time_zone': 'Alaska',\n",
|
|
" 'translator_type': 'none',\n",
|
|
" 'url': None,\n",
|
|
" 'utc_offset': -28800,\n",
|
|
" 'verified': False}"
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"credentials = {\n",
|
|
" 'user': 'bitter test',\n",
|
|
" 'consumer_key': os.environ.get('CONSUMER_KEY', '<YOUR CONSUMER KEY>'),\n",
|
|
" 'consumer_secret': os.environ.get('CONSUMER_SECRET', '<YOUR CONSUME SECRET>'),\n",
|
|
" 'token_key': os.environ.get('ACCESS_TOKEN', '<YOUR ACCESS TOKEN>'),\n",
|
|
" 'token_secret': os.environ.get('ACCESS_TOKEN_SECRET', 'YOUR ACCESS TOKEN SECRET>')\n",
|
|
"}\n",
|
|
"from bitter.crawlers import RestWorker\n",
|
|
"t = RestWorker('bitter_test', credentials)\n",
|
|
"t.client.users.show(screen_name='torvalds')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"for tweet in t.client.search.tweets(q='linux')['statuses']:\n",
|
|
" print(tweet['text'])"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.6.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
} |