From 1de03e0e0d62010fa70723f6cb187c5988e8f6bd Mon Sep 17 00:00:00 2001 From: Pragya Khanna <75221153+pragyakhanna11@users.noreply.github.com> Date: Thu, 10 Jun 2021 13:48:42 +0530 Subject: [PATCH] Delete Twitter_API.ipynb --- APIScripts/Twitter API/Twitter_API.ipynb | 431 ----------------------- 1 file changed, 431 deletions(-) delete mode 100644 APIScripts/Twitter API/Twitter_API.ipynb diff --git a/APIScripts/Twitter API/Twitter_API.ipynb b/APIScripts/Twitter API/Twitter_API.ipynb deleted file mode 100644 index 183235e10..000000000 --- a/APIScripts/Twitter API/Twitter_API.ipynb +++ /dev/null @@ -1,431 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "Twitter API.ipynb", - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, - "cells": [ - { - "cell_type": "code", - "metadata": { - "id": "JTQaMODoslBA" - }, - "source": [ - "#import necessary libraries\n", - "\n", - "from google.colab import drive # to mount Google Drive to Colab notebook\n", - "import tweepy # Python wrapper around Twitter API\n", - "import pandas as pd\n", - "import csv\n", - "from datetime import date\n", - "from datetime import datetime\n", - "import time" - ], - "execution_count": 1, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "FnCAO05tsrrv", - "outputId": "964984c5-506b-4c67-ac34-f56e23c7a4a5" - }, - "source": [ - "# Mounting Google Drive\n", - "\n", - "drive.mount('/content/gdrive')\n", - "path = './gdrive/My Drive/'" - ], - "execution_count": 2, - "outputs": [ - { - "output_type": "stream", - "text": [ - "Mounted at /content/gdrive\n" - ], - "name": "stdout" - } - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "XsuHMNlbyPgv" - }, - "source": [ - "# Load Twitter API secrets from an external file\n", - "secrets = pd.read_csv('/content/gdrive/MyDrive/secrets.csv')\n", - "\n", - "consumer_key = secrets['consumer_key'][0]\n", - "consumer_secret = secrets['consumer_secret'][0]\n", - "access_token = secrets['access_token'][0]\n", - "access_token_secret = secrets['access_token_secret'][0]\n", - "\n", - "auth = tweepy.OAuthHandler(consumer_key, consumer_secret)\n", - "auth.set_access_token(access_token, access_token_secret)\n", - "auth.secure = True\n", - "api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)" - ], - "execution_count": 3, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "id": "RLPxR7uI2Dke" - }, - "source": [ - "# Helper function to handle twitter API rate limit\n", - "\n", - "def limit_handled(cursor, list_name):\n", - " while True:\n", - " try:\n", - " yield cursor.next()\n", - " except tweepy.RateLimitError:\n", - " print(\"\\nCurrent number of data points in list = \" + str(len(list_name)))\n", - " print('Hit Twitter API rate limit.')\n", - " for i in range(3, 0, -1):\n", - " print(\"Wait for {} mins.\".format(i * 5))\n", - " time.sleep(5 * 60)\n", - " except tweepy.error.TweepError:\n", - " print('\\nCaught TweepError exception' )" - ], - "execution_count": 4, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "id": "6oqW0rNY2Mjt" - }, - "source": [ - "# Helper function to get all tweets for a specified user\n", - "\n", - "def user_tweets(screen_name, number_of_tweets):\n", - "\n", - " # A list to hold all tweets by tweepy\n", - "\talltweets = []\t\n", - "\n", - " # To extract initial 200 tweets(most recent)\n", - "\tnew_tweets = api.user_timeline(screen_name = screen_name,count=200)\n", - "\n", - " # Add these to the list\n", - "\talltweets.extend(new_tweets)\n", - "\n", - " # save the id of the oldest tweet less one\n", - "\toldest = alltweets[-1].id - 1\n", - "\n", - " # keep grabbing tweets until we reach the desired limit\n", - "\twhile(len(alltweets)\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
idcreated_attextlikesin reply toretweeted
014028828912611328002021-06-10 06:58:40RT @mattgaetz: My opponent is the Typhoid Mary...0NaNFalse
114028828911309619212021-06-10 06:58:40RT @AnnastaciaMP: Thursday 10 June – coronavir...0NaNFalse
214028828907408998412021-06-10 06:58:40RT @HumasPoldaAceh: Sistem Bubble yang akan di...0NaNFalse
314028828906947297292021-06-10 06:58:40@aadesh_pande @MNageswarRaoIPS @PypAyurved @sh...0aadesh_pandeFalse
414028828905941442562021-06-10 06:58:40RT @PolForFreedom: Belangrijke keuzes in het l...0NaNFalse
.....................
59514028826711355105322021-06-10 06:57:47RT @SharynLeeMcG: Perth people, please get alo...0NaNFalse
59614028826709929656392021-06-10 06:57:47RT @drozcanyucel: Hocam bir insana Aspirin bil...0NaNFalse
59714028826700031098882021-06-10 06:57:47RT @infofoundationx: I've just been told by a ...0NaNFalse
59814028826691852206102021-06-10 06:57:47RT @terrybowman60: @Psyop2020 @crbarnes001 \"ma...0NaNFalse
59914028826685224017922021-06-10 06:57:47RT @sunaibkk: อย่ามั่ว! ประยุทธ์พูดกลางสภาว่าท...0NaNFalse
\n", - "

600 rows × 6 columns

\n", - "" - ], - "text/plain": [ - " id created_at ... in reply to retweeted\n", - "0 1402882891261132800 2021-06-10 06:58:40 ... NaN False\n", - "1 1402882891130961921 2021-06-10 06:58:40 ... NaN False\n", - "2 1402882890740899841 2021-06-10 06:58:40 ... NaN False\n", - "3 1402882890694729729 2021-06-10 06:58:40 ... aadesh_pande False\n", - "4 1402882890594144256 2021-06-10 06:58:40 ... NaN False\n", - ".. ... ... ... ... ...\n", - "595 1402882671135510532 2021-06-10 06:57:47 ... NaN False\n", - "596 1402882670992965639 2021-06-10 06:57:47 ... NaN False\n", - "597 1402882670003109888 2021-06-10 06:57:47 ... NaN False\n", - "598 1402882669185220610 2021-06-10 06:57:47 ... NaN False\n", - "599 1402882668522401792 2021-06-10 06:57:47 ... NaN False\n", - "\n", - "[600 rows x 6 columns]" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 8 - } - ] - } - ] -} \ No newline at end of file