Skip to content

Commit

Permalink
fix: now save the translated file
Browse files Browse the repository at this point in the history
  • Loading branch information
Phosphorus-M committed Jan 16, 2024
1 parent 4653ef9 commit e9c062e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/this_week_in_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ jobs:
echo " - comunidad">>"$DATE-this-week-in-rust.md"
echo ' - "esta semana en rust"'>>"$DATE-this-week-in-rust.md"
echo -e "---\n">>"$DATE-this-week-in-rust.md"
- name: Show folder!
run: |
ls -la
echo "----"
echo "Seteo permisos"
chmod 777 "./$DATE-this-week-in-rust.md"
echo "----"
ls -la
- name: Translate File
id: translation_step
env:
Expand Down
15 changes: 13 additions & 2 deletions gen_translated.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
}

# You can pass more than one object in body.
original_text = raw_file.read()

body = [{
'text' : raw_file.read()
'text': original_text
}]
request = requests.post(constructed_url, headers=headers, json=body)
response = request.json()
Expand All @@ -49,7 +50,15 @@
# generate ouput
meta_content = open(raw_date + "-this-week-in-rust.md", "r").read()
with open(raw_date + "-this-week-in-rust.md", 'w') as fh:
content = response[0]["translations"][0]["text"]
content = ""
if response and "translations" in response[0] and response[0]["translations"]:
content = response[0]["translations"][0]["text"]
else:
content = original_text
print('No se pudo traducir')
print("Response: ")
print(response)

description = [line for line in content.split('\n') if line.startswith("La caja de esta semana es")]
print(f"Match = {description}")
description = description[0]
Expand All @@ -65,4 +74,6 @@
new_content = meta_content.replace("Esta semana en Rust es un blog semanal sobre el lenguaje de programación Rust, sus comunidades y su ecosistema.", link_name)
print(f"Replacement Result: {new_content}")
content = new_content + '\n' + content

fh.write(content)

0 comments on commit e9c062e

Please sign in to comment.