From 5eb53297cc99b4ddf8513eeaa90b700e41e5899d Mon Sep 17 00:00:00 2001 From: kumarks1122 Date: Thu, 8 Feb 2024 23:07:23 +0530 Subject: [PATCH] #000 | Generate config script changes added: --- .github/workflows/docker-image.yml | 3 --- README.md | 2 +- config.yaml | 1 + generate-config.py | 23 +++++++++++++---------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index f878cf0..e1931ef 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -7,11 +7,8 @@ on: branches: [ "main" ] jobs: - build: - runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 - name: Build the Docker image diff --git a/README.md b/README.md index b880138..ac2a131 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ region_name: "" aws_secret_access_key: "" aws_access_key_id: "" endpoint_url: "" - +bucket: "" ``` ### Step 3 diff --git a/config.yaml b/config.yaml index 2efe9c1..2826b27 100644 --- a/config.yaml +++ b/config.yaml @@ -2,3 +2,4 @@ region_name: "" aws_secret_access_key: "" aws_access_key_id: "" endpoint_url: "" +bucket: "" \ No newline at end of file diff --git a/generate-config.py b/generate-config.py index 2e8aac2..e191aa8 100644 --- a/generate-config.py +++ b/generate-config.py @@ -9,6 +9,8 @@ from pathlib import Path +CONFIG = {} + def get_upload_path(file_name, category, language): if category != "" and language != "": return f'audio/{category}/{language}/{file_name}' @@ -17,8 +19,9 @@ def get_upload_path(file_name, category, language): def upload_to_oci_storage(s3, file_name, category, language): try: - upload_path = get_upload_path(file_name, category, language) - s3.meta.client.upload_file(f"drive-files/{file_name}", 'sbdjp-ivrs', upload_path) + file_path = Path(file_name) + upload_path = get_upload_path(file_path.name, category, language) + s3.meta.client.upload_file(f"drive-files/{file_name}", CONFIG['bucket'], upload_path) print(upload_path, "uploaded successfully") except Exception as e: print(e) @@ -28,9 +31,9 @@ def create_config(s3): categories = set() languages = set() - invalid_option_link = ["https://objectstorage.ap-hyderabad-1.oraclecloud.com/n/ax2cel5zyviy/b/sbdjp-ivrs/o/audio/invalid_option_english.wav"] + invalid_option_link = ["https://objectstorage.ap-hyderabad-1.oraclecloud.com/n/ax2cel5zyviy/b/sbdjp-ivrs/o/audio/invalid_option_english.mp3"] - for obj in s3.Bucket('sbdjp-ivrs').objects.all(): + for obj in s3.Bucket(CONFIG['bucket']).objects.all(): path = Path(obj.key) if len(path.parts) < 4: continue @@ -45,7 +48,7 @@ def create_config(s3): audio_key = f"{category}:{language}" if audio_key not in config: config[audio_key] = [] - url = s3.meta.client.generate_presigned_url(ClientMethod = 'get_object', Params = { 'Bucket': 'sbdjp-ivrs', 'Key': obj.key }) + url = s3.meta.client.generate_presigned_url(ClientMethod = 'get_object', Params = { 'Bucket': CONFIG['bucket'], 'Key': obj.key }) url = url.split("?")[0] config[audio_key].append(url) @@ -68,13 +71,13 @@ def create_config(s3): exit(1) with open("config.yaml", "r") as stream: - config = yaml.safe_load(stream) + CONFIG = yaml.safe_load(stream) s3 = boto3.resource( 's3', - region_name=config["region_name"], - aws_secret_access_key=config["aws_secret_access_key"], - aws_access_key_id=config["aws_access_key_id"], - endpoint_url=config["endpoint_url"] + region_name=CONFIG["region_name"], + aws_secret_access_key=CONFIG["aws_secret_access_key"], + aws_access_key_id=CONFIG["aws_access_key_id"], + endpoint_url=CONFIG["endpoint_url"] ) with open(sys.argv[1]) as csv_file: