Skip to content

Commit

Permalink
Create download_model.py
Browse files Browse the repository at this point in the history
  • Loading branch information
k0T0z committed Jul 15, 2024
1 parent 284abaf commit b7b1fa5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions download_gdrive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import requests
import os
import sys

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__":
if len(sys.argv) != 3:
print("Usage: python download_gdrive.py drive_file_id destination_path")
sys.exit(1)

file_id = sys.argv[1]
destination = sys.argv[2]
download_file_from_google_drive(file_id, destination)

0 comments on commit b7b1fa5

Please sign in to comment.