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] --- 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 +}