Last active
October 10, 2019 03:10
-
-
Save brockmanmatt/39c6a06834a9a154bd5c8ad0ee2ca5f3 to your computer and use it in GitHub Desktop.
Medium Modeling News 2 - Check GDELT files exist
This file contains hidden or 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
!pip install gdelt | |
import gdelt | |
gd = gdelt.gdelt(version=1) | |
import os, datetime | |
os.makedirs("data",exist_ok=True) | |
#starting 60 days before Oct7 | |
cur_date = datetime.datetime(2019,10,7)-datetime.timedelta(days=60) | |
end_date = datetime.datetime(2019,10,7) | |
#check if already have each day; if not, pull it | |
while cur_date < end_date: | |
print("%s-%s-%s"%(cur_date.year, cur_date.month, cur_date.day)) | |
if not os.path.exists("data/%s-%s-%s.pkl"%(cur_date.year, cur_date.month, cur_date.day)): | |
year = cur_date.year | |
month = str(cur_date.month) | |
day = str(cur_date.day) | |
if cur_date.month < 10: | |
month = "0"+month | |
if cur_date.day < 10: | |
day = "0"+day | |
results = gd.Search(['%s %s %s'%(year, month, day)],table='gkg',coverage=True, translation=False) | |
results.to_pickle("data/%s-%s-%s.pkl"%(cur_date.year, cur_date.month, cur_date.day)) | |
cur_date+=datetime.timedelta(days=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment