Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python script for downloading files from googledrive

import requests

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

    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)

if __name__ == "__main__":
    file_id = 'TAKE ID FROM SHAREABLE LINK'
    destination = 'DESTINATION FILE ON YOUR DISK'
    download_file_from_google_drive(file_id, destination)
Comment

PREVIOUS NEXT
Code Example
Python :: pdf to excel conversion using python 
Python :: telegram.ext package python 
Python :: merge sort of two list in python 
Python :: Reading Custom Delimited file in python 
Python :: subplot ytick percent 
Python :: python jointly shuffle list 
Python :: Python Alphabet using list comprehension 
Python :: how to convert frame number in seconds python 
Python :: Get percentage of missing values pyspark all columns 
Python :: how to plot a single cluster 
Python :: time python 
Python :: Example code of while loop in python 
Python :: STATPC 
Python :: how to plot side by side bar horizontal bar graph in python 
Python :: how to use ActionChains selenium python with WebDriverWait 
Python :: how to sort in python 
Python :: how to get ping from computer IN PYTHON 
Python :: Prints all integers of a list 
Python :: seaborn bar plot sort for weekday 
Python :: how to remove axis in matplotlib 
Python :: hide grid imshow 
Python :: gdscript fixed decimal 
Python :: python append to a exiting csv file 
Python :: python switch 
Python :: pandas data frame from part of excel better example 
Python :: python delete column 
Python :: Converting a HDFDataset to numpy array 
Python :: python clear memory 
Python :: Python Permutation without built-in function [itertools] for Lists 
Python :: unique list 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =