Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 116 additions & 147 deletions Ch8/01_WordCloud.ipynb

Large diffs are not rendered by default.

51 changes: 32 additions & 19 deletions Ch8/02_DifferentTokenizers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 0,
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -19,23 +19,36 @@
"text": [
"Collecting twikenizer\n",
" Downloading https://files.pythonhosted.org/packages/d2/51/7aee33630b948f0716efae7a96c4fd8f859b348694058c380fd899a4227e/twikenizer-1.0.tar.gz\n",
"Building wheels for collected packages: twikenizer\n",
" Building wheel for twikenizer (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for twikenizer: filename=twikenizer-1.0-cp36-none-any.whl size=4853 sha256=69c74c1ea248414aa18ccbf0d8f0b704cb204a0af7fd1a75d3821a783b301b83\n",
" Stored in directory: /root/.cache/pip/wheels/34/5d/df/2bf827d7e3c6bda2b2dcdd978f975afd43ef400784c9507675\n",
"Successfully built twikenizer\n",
"Installing collected packages: twikenizer\n",
"Successfully installed twikenizer-1.0\n",
" Running setup.py install for twikenizer: started\n",
" Running setup.py install for twikenizer: finished with status 'done'\n",
"Successfully installed twikenizer-1.0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"You are using pip version 19.0.3, however version 21.1.2 is available.\n",
"You should consider upgrading via the 'python -m pip install --upgrade pip' command.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting emoji\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/40/8d/521be7f0091fe0f2ae690cc044faf43e3445e0ff33c574eae752dd7e39fa/emoji-0.5.4.tar.gz (43kB)\n",
"\u001b[K |████████████████████████████████| 51kB 1.7MB/s \n",
"\u001b[?25hBuilding wheels for collected packages: emoji\n",
" Building wheel for emoji (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for emoji: filename=emoji-0.5.4-cp36-none-any.whl size=42176 sha256=13fd92618dda624b5bf58512c35020d306717a1ffbb07b067cea5ef79ca2ba2e\n",
" Stored in directory: /root/.cache/pip/wheels/2a/a9/0a/4f8e8cce8074232aba240caca3fade315bb49fac68808d1a9c\n",
"Successfully built emoji\n",
" Downloading https://files.pythonhosted.org/packages/24/fa/b3368f41b95a286f8d300e323449ab4e86b85334c2e0b477e94422b8ed0f/emoji-1.2.0-py3-none-any.whl (131kB)\n",
"Installing collected packages: emoji\n",
"Successfully installed emoji-0.5.4\n"
"Successfully installed emoji-1.2.0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"You are using pip version 19.0.3, however version 21.1.2 is available.\n",
"You should consider upgrading via the 'python -m pip install --upgrade pip' command.\n"
]
}
],
Expand All @@ -46,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": 2,
"metadata": {
"colab": {},
"colab_type": "code",
Expand All @@ -59,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand All @@ -86,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": 5,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
Expand Down Expand Up @@ -132,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
269 changes: 131 additions & 138 deletions Ch8/03_TrendingTopics.ipynb
Original file line number Diff line number Diff line change
@@ -1,115 +1,108 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "TrendingTopics.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "6IM1xuTnGlPs"
},
"source": [
"# Trending Topics\n",
"\n",
"## In this notebook we show you how to access the most trending topics in a particular location. \n",
"### pre-requisites: Twitter Developer Account. If you dont have one, dont worry it is free to obtain all you need to do is visit this link and follow the setup process explained [here](https://cran.r-project.org/web/packages/rtweet/vignettes/auth.html)."
]
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "6IM1xuTnGlPs",
"colab_type": "text"
},
"source": [
"#Trending Topics\n",
"\n",
"##In this notebook we show you how to access the most trending topics in a particular locatoin. \n",
"###pre-requisites: Twitter Developer Account. If you dont have one, dont worry it is free to obtain all you need to do is visit this link and follow the setup process explained [here](https://cran.r-project.org/web/packages/rtweet/vignettes/auth.html)."
]
},
{
"cell_type": "code",
"metadata": {
"id": "SSKP1W_7p7vL",
"colab_type": "code",
"colab": {}
},
"source": [
"import tweepy, json"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "toSpm2I4BeTH",
"colab_type": "code",
"colab": {}
},
"source": [
"#setting all the credentials of your twitter developer account\n",
"CONSUMER_KEY= 'insert your customer key'\n",
"CONSUMER_SECRET= 'insert your customer secrect key'\n",
"ACCESS_KEY= 'insert your access key here'\n",
"ACCESS_SECRET= 'insert your access secret key here'"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "oiNcCJPiBfDW",
"colab_type": "code",
"colab": {}
},
"source": [
"#granting access to your twitter account\n",
"auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)\n",
"auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)\n",
"api = tweepy.API(auth)"
],
"execution_count": 0,
"outputs": []
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "SSKP1W_7p7vL"
},
"outputs": [],
"source": [
"import tweepy, json"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "toSpm2I4BeTH"
},
"outputs": [],
"source": [
"# Setting all the credentials of your twitter developer account.\n",
"\n",
"CONSUMER_KEY= 'insert your customer key'\n",
"CONSUMER_SECRET= 'insert your customer secrect key'\n",
"ACCESS_KEY= 'insert your access key here'\n",
"ACCESS_SECRET= 'insert your access secret key here'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "oiNcCJPiBfDW"
},
"outputs": [],
"source": [
"# Granting access to your twitter account.\n",
"\n",
"auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)\n",
"auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)\n",
"api = tweepy.API(auth)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
{
"cell_type": "code",
"metadata": {
"id": "wAM5FWYPBix2",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "d474a149-e0dc-440f-a723-c273f0a112ae"
},
"source": [
"#A WOEID (Where On Earth IDentifier) is a unique 32-bit reference identifier\n",
"\n",
"WORLD_WOE_ID =1\n",
"BRAZIL_WOE_ID = 23424768\n",
"\n",
"#fetching trending topics in brazil \n",
"brazil_trends = api.trends_place(BRAZIL_WOE_ID)\n",
"trends = json.loads(json.dumps(brazil_trends, indent=1))\n",
" \n",
"brazil_trend_list=[] \n",
"for trend in trends[0][\"trends\"]:\n",
"\tbrazil_trend_list.append(trend[\"name\"].strip(\"#\"))\n",
"\n",
"#fetching trending topics in the world\n",
"world_trends = api.trends_place(WORLD_WOE_ID)\n",
"world_trends_json = json.loads(json.dumps(world_trends, indent=1))\n",
"\n",
"world_trend_list=[] \n",
"for trend in world_trends_json[0][\"trends\"]:\n",
"\tworld_trend_list.append(trend[\"name\"].strip(\"#\"))\n",
" \n",
"#printing the topics which are trending in both WORLD and BRAZIL \n",
"print(set(world_trend_list).intersection(set(brazil_trend_list)))"
],
"execution_count": 29,
"outputs": [
"colab_type": "code",
"id": "wAM5FWYPBix2",
"outputId": "d474a149-e0dc-440f-a723-c273f0a112ae"
},
"outputs": [],
"source": [
"# A WOEID (Where On Earth IDentifier) is a unique 32-bit reference identifier.\n",
"\n",
"WORLD_WOE_ID =1\n",
"BRAZIL_WOE_ID = 23424768\n",
"\n",
"# Fetching trending topics in BraziL.\n",
"\n",
"brazil_trends = api.trends_place(BRAZIL_WOE_ID)\n",
"trends = json.loads(json.dumps(brazil_trends, indent=1))\n",
" \n",
"brazil_trend_list=[] \n",
"for trend in trends[0][\"trends\"]:\n",
"\tbrazil_trend_list.append(trend[\"name\"].strip(\"#\"))\n",
"\n",
"# Fetching trending topics in the world.\n",
"world_trends = api.trends_place(WORLD_WOE_ID)\n",
"world_trends_json = json.loads(json.dumps(world_trends, indent=1))\n",
"\n",
"world_trend_list=[] \n",
"for trend in world_trends_json[0][\"trends\"]:\n",
"\tworld_trend_list.append(trend[\"name\"].strip(\"#\"))\n",
" \n",
"# Printing the topics which are trending in both WORLD and BRAZIL.\n",
"\n",
"print(set(world_trend_list).intersection(set(brazil_trend_list)))"
],
"execution_count": 29,
"outputs": [
{
"output_type": "stream",
"text": [
Expand All @@ -118,32 +111,32 @@
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "CvD89_eKCF7d",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "PPpiCPOwDGLO",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "TrendingTopics.ipynb",
"provenance": []
},
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading