This notebook will walk through on how to download the test data necessary for the demo
Last Update: 10/12/2017
In [17]:
# imports
import requests
import zipfile
import os
In [18]:
# Methods to pull from google drive
def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params = { 'id' : id }, stream = True)
token = get_confirm_token(response)
if token:
params = { 'id' : id, 'confirm' : token }
response = session.get(URL, params = params, stream = True)
save_response_content(response, destination)
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, destination):
CHUNK_SIZE = 32768 #iterate by chunks of data to not loose information
with open(destination, "wb") as f:
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
In [19]:
# download the zip
file_id = '0Bx1nyj-4aTk9RnNnS3JfRDZ6MVU' # the ID to the file on Google Drive
destination = 'public_data.zip'
# pass through the arguements
download_file_from_google_drive(file_id, destination)
In [20]:
# unzip the data
zip_ref = zipfile.ZipFile(destination, 'r')
zip_ref.extractall(os.getcwd())
zip_ref.close()
In [ ]: