Skip to content

Commit

Permalink
fix(remove awscli): removes dependency on awscli for retrieving publi…
Browse files Browse the repository at this point in the history
…c data
  • Loading branch information
sqr00t committed Sep 27, 2023
1 parent 1141278 commit 0af4119
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion ojd_daps_skills/getters/download_public_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def download():

public_data_dir = os.path.join(PROJECT_DIR, PUBLIC_DATA_FOLDER_NAME)

os.system(
Expand All @@ -14,5 +13,43 @@ def download():
os.system(f"rm {public_data_dir}.zip")


if __name__ == "__main__":
download()

from ojd_daps_skills import PUBLIC_DATA_FOLDER_NAME, PROJECT_DIR

import os
import boto3
from botocore.exceptions import ClientError
from botocore import UNSIGNED
from botocore.config import Config
from zipfile import ZipFile


def download():
"""Download public data. Expected to run once on first use."""
s3 = boto3.client(
"s3", region_name="eu-west-1", config=Config(signature_version=UNSIGNED)
)

bucket_name = "open-jobs-indicators"
key = f"escoe_extension/{PUBLIC_DATA_FOLDER_NAME}.zip"

public_data_dir = os.path.join(PROJECT_DIR, PUBLIC_DATA_FOLDER_NAME)

try:
s3.download_file(bucket_name, key, f"{public_data_dir}.zip")

with ZipFile(f"{public_data_dir}.zip", "r") as zip_ref:
zip_ref.extractall(PROJECT_DIR)

os.remove(f"{public_data_dir}.zip")

except ClientError as ce:
print(f"Error: {ce}")
except FileNotFoundError as fnfe:
print(f"Error: {fnfe}")


if __name__ == "__main__":
download()

0 comments on commit 0af4119

Please sign in to comment.