Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Add http support to model downloading #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/file_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
import os
import gdown
import zipfile
<<<<<<< Updated upstream
=======
import click
import requests
>>>>>>> Stashed changes

def extract_id_from_google_drive_share_link(drive_link):
return drive_link


def download_file(url, local_filename):
# local_filename = url.split('/')[-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be deleted, I think.

# NOTE the stream=True parameter below
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
# If you have chunk encoded response uncomment if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "chunk encoded response" mean?

# and set chunk_size parameter to None.
#if chunk:
f.write(chunk)
return local_filename

"""
Example model json format
"models": [
Expand Down Expand Up @@ -44,8 +55,7 @@ def extract_id_from_google_drive_share_link(drive_link):
print(url, output)
gdown.download(url, output, quiet=False)
if provider == "http" or provider == "https":
r = requests.get(url)
open(output, 'wb').write(r.content)
download_file(url, output)
else:
raise UnsupportedOperation()

Expand Down