pydrive download by url

Solutions on MaxInterview for pydrive download by url by the best coders in the world

showing results for - "pydrive download by url"
Jana
11 Apr 2017
1import requests
2
3def download_file_from_google_drive(id, destination):
4    URL = "https://docs.google.com/uc?export=download"
5
6    session = requests.Session()
7
8    response = session.get(URL, params = { 'id' : id }, stream = True)
9    token = get_confirm_token(response)
10
11    if token:
12        params = { 'id' : id, 'confirm' : token }
13        response = session.get(URL, params = params, stream = True)
14
15    save_response_content(response, destination)    
16
17def get_confirm_token(response):
18    for key, value in response.cookies.items():
19        if key.startswith('download_warning'):
20            return value
21
22    return None
23
24def save_response_content(response, destination):
25    CHUNK_SIZE = 32768
26
27    with open(destination, "wb") as f:
28        for chunk in response.iter_content(CHUNK_SIZE):
29            if chunk: # filter out keep-alive new chunks
30                f.write(chunk)
31
32if __name__ == "__main__":
33    file_id = 'TAKE ID FROM SHAREABLE LINK'
34    destination = 'DESTINATION FILE ON YOUR DISK'
35    download_file_from_google_drive(file_id, destination)
36
Oskar
08 May 2020
1for file1 in file_list:
2    if file1['title'] == '[name_of_target_folder]':
3        folder_id = file1['id']
4
Luca
16 Jul 2020
1file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(folder_id)}).GetList()
2