diff --git a/app/proxy.py b/app/proxy.py index 7e30e4603f39d481c89d7208b71b6fe62e67bbe4..981c4d415c734eefef5bfbe858dd45df0bf74d15 100644 --- a/app/proxy.py +++ b/app/proxy.py @@ -5,6 +5,8 @@ from zipfile import ZipFile app = Flask(__name__) +######################################################################################### + def get_collection_ids(collection_id): url = f"https://api.portalmec.c3sl.ufpr.br/v1/collections/{collection_id}" response = requests.get(url) @@ -16,6 +18,8 @@ def get_collection_ids(collection_id): ids.append(file_data['collectionable']['id']) return ids +######################################################################################### + def download_files(ids): downloaded_files = [] for file_id in ids: @@ -24,6 +28,8 @@ def download_files(ids): downloaded_files.append(filename) return downloaded_files +######################################################################################### + def download_file(url): with requests.get(url, stream=True, verify=False) as r: r.raise_for_status() @@ -38,12 +44,16 @@ def download_file(url): return filename +######################################################################################### + def create_zip(files, collection_id): with ZipFile(f"colecao_{collection_id}.zip", 'w') as zip: for file in files: zip.write(file) os.remove(file) +######################################################################################### + @app.route('/<collection_id>', methods=['GET']) def download_zip(collection_id): try: