-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2 Added a simple yesterday last 15 mins query
- Loading branch information
1 parent
ee11923
commit f468c7b
Showing
1 changed file
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Requirements" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Requirement already satisfied: gdelt in c:\\users\\developer\\appdata\\roaming\\python\\python36\\site-packages (0.1.10.6)\n", | ||
"Requirement already satisfied: numpy in c:\\users\\developer\\appdata\\roaming\\python\\python36\\site-packages (from gdelt) (1.18.1)\n", | ||
"Requirement already satisfied: pandas>=0.20.3 in c:\\users\\developer\\appdata\\roaming\\python\\python36\\site-packages (from gdelt) (1.0.1)\n", | ||
"Requirement already satisfied: python-dateutil in c:\\bin\\anaconda3\\lib\\site-packages (from gdelt) (2.6.1)\n", | ||
"Requirement already satisfied: requests in c:\\users\\developer\\appdata\\roaming\\python\\python36\\site-packages (from gdelt) (2.22.0)\n", | ||
"Requirement already satisfied: pytz>=2017.2 in c:\\bin\\anaconda3\\lib\\site-packages (from pandas>=0.20.3->gdelt) (2017.3)\n", | ||
"Requirement already satisfied: six>=1.5 in c:\\bin\\anaconda3\\lib\\site-packages (from python-dateutil->gdelt) (1.11.0)\n", | ||
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\\bin\\anaconda3\\lib\\site-packages (from requests->gdelt) (1.22)\n", | ||
"Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\\bin\\anaconda3\\lib\\site-packages (from requests->gdelt) (3.0.4)\n", | ||
"Requirement already satisfied: certifi>=2017.4.17 in c:\\bin\\anaconda3\\lib\\site-packages (from requests->gdelt) (2019.11.28)\n", | ||
"Requirement already satisfied: idna<2.9,>=2.5 in c:\\bin\\anaconda3\\lib\\site-packages (from requests->gdelt) (2.6)\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"You are using pip version 18.1, however version 20.0.2 is available.\n", | ||
"You should consider upgrading via the 'python -m pip install --upgrade pip' command.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"!pip install --user gdelt" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Import modules" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from datetime import date, timedelta\n", | ||
"from gdelt import gdelt as gdelt_client\n", | ||
"import matplotlib.pyplot as plot\n", | ||
"import seaborn" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Query the knowledge graph" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 17, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_graph(date):\n", | ||
" client = gdelt_client(version=2)\n", | ||
" events = client.Search(date.strftime(\"%Y %m %d\"), table=\"gkg\", coverage=False)\n", | ||
" del client\n", | ||
" return events\n", | ||
"\n", | ||
"def get_today_graph():\n", | ||
" return get_graph(date.today())\n", | ||
"\n", | ||
"def get_yesterday_graph():\n", | ||
" return get_graph(date.today()-timedelta(days=1))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"0 False\n", | ||
"1 False\n", | ||
"2 True\n", | ||
"3 True\n", | ||
"4 NaN\n", | ||
" ... \n", | ||
"2256 True\n", | ||
"2257 False\n", | ||
"2258 False\n", | ||
"2259 False\n", | ||
"2260 False\n", | ||
"Name: V2Themes, Length: 2261, dtype: object" | ||
] | ||
}, | ||
"execution_count": 19, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"graph = get_yesterday_graph()\n", | ||
"graph[\"V2Themes\"].str.contains(\"TAX_DISEASE_CORONAVIRUS\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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 | ||
} |