Skip to content

Commit

Permalink
Merge pull request #3 from kumarks1122/main
Browse files Browse the repository at this point in the history
Generate config script changes added:
  • Loading branch information
maheshkumargangula authored Feb 9, 2024
2 parents d38d155 + 5eb5329 commit 8362c06
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ on:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ region_name: ""
aws_secret_access_key: ""
aws_access_key_id: ""
endpoint_url: ""
bucket: ""
```

### Step 3
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ region_name: ""
aws_secret_access_key: ""
aws_access_key_id: ""
endpoint_url: ""
bucket: ""
23 changes: 13 additions & 10 deletions generate-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 8362c06

Please sign in to comment.