From ca55b5112970d2619f1e760fc284fce143aae72c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 21 Mar 2019 16:02:03 +0100 Subject: [PATCH 1/5] --- tutorial.ipynb | 161 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tutorial.ipynb diff --git a/tutorial.ipynb b/tutorial.ipynb new file mode 100644 index 0000000..01f7fba --- /dev/null +++ b/tutorial.ipynb @@ -0,0 +1,161 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " import bitter\n", + "except ImportError:\n", + " import pip\n", + " pip.main(['install', '--user', 'bitter'])\n", + " import bitter\n", + "import os" + ] + }, + { + "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': 'Twitter Web Client',\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', ''),\n", + " 'consumer_secret': os.environ.get('CONSUMER_SECRET', ''),\n", + " 'token_key': os.environ.get('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 +} From f803f9701e1a9a3d1d2071ee2e8b951797163b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 21 Mar 2019 16:07:11 +0100 Subject: [PATCH 2/5] --- tutorial.ipynb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index 01f7fba..51b8b8f 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -6,12 +6,13 @@ "metadata": {}, "outputs": [], "source": [ - "try:\n", - " import bitter\n", - "except ImportError:\n", - " import pip\n", - " pip.main(['install', '--user', 'bitter'])\n", - " import bitter\n", + "# 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 -r requirements.txt", "import os" ] }, @@ -158,4 +159,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file From 3381020cb9914a7c2621c2eebd4866864e97ac84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 21 Mar 2019 16:07:53 +0100 Subject: [PATCH 3/5] --- tutorial.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index 51b8b8f..351f0bd 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -12,7 +12,7 @@ "usersite = site.getusersitepackages()\n", "if usersite not in sys.path:\n", " sys.path.append(usersite)\n", - "!{sys.executable} -m pip install --user -r requirements.txt", + "!{sys.executable} -m pip install --user bitter", "import os" ] }, From e14b7ed50ce27267785855b6785c44c9ff1e662f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 21 Mar 2019 16:08:35 +0100 Subject: [PATCH 4/5] --- tutorial.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index 351f0bd..a8a54e4 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -13,7 +13,8 @@ "if usersite not in sys.path:\n", " sys.path.append(usersite)\n", "!{sys.executable} -m pip install --user bitter", - "import os" + "import os", + "import bitter" ] }, { From 04ad72df5841c69034d96a8abab3c604fdd07c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Thu, 21 Mar 2019 16:09:29 +0100 Subject: [PATCH 5/5] --- tutorial.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index a8a54e4..4c849c6 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -12,9 +12,9 @@ "usersite = site.getusersitepackages()\n", "if usersite not in sys.path:\n", " sys.path.append(usersite)\n", - "!{sys.executable} -m pip install --user bitter", - "import os", - "import bitter" + "!{sys.executable} -m pip install --user bitter\n", + "import os\n", + "import bitter\n" ] }, {