Skip to content

Instantly share code, notes, and snippets.

@facundoq facundoq/various.py
Created Apr 15, 2019

Embed
What would you like to do?
Structuring downloads
from abc import ABC,abstractmethod
class DownloadFile(ABC):
def __init__(self, url, filepath):
self.url = url
self.filepath = filepath
@abstractmethod
def download(self):
pass
class DownloadError(Exception):
def __init__(self,download_file,error):
self.download_file=download_file
self.error=error
class DownloadFileHTTP(DownloadFile):
def download(self):
#<do the download>
# if download unsuccesfull, raise DownloadError(self,reason)
#...
class XYZDatasetLoader(DatasetLoader):
def __init__(self,folderpath):
self.download_files=[ DownloadFileHTTP("archivo1.zip",os.path.join(folderpath,"a1.zip"))
,DownloadFileHTTP("archivo2.zip",os.path.join(folderpath,"a2.zip"))
]
#....
class DatasetLoader():
@property
@abstractmethod
def download_files(self):
pass
#..... all other stuff
def download_dataset(self):
for download_file in self.download_files:
download_file.download()
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.