Skip to content

Commit

Permalink
Adds commenting, docstring for get_translation_result
Browse files Browse the repository at this point in the history
  • Loading branch information
cr2007 committed Jun 25, 2024
1 parent 569b98a commit f648f5e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cambai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,17 +1203,30 @@ def create_translation(
def get_translation_result(
self, /, run_id: int, *, save_to_file: bool = False
) -> TranslationResult:
"""
Retrieves the translation result for a given run ID.
Args:
self (object): The instance of the class.
run_id (int): The ID of the translation run.
save_to_file (bool): Whether to save the result to a file. Defaults to False.
Returns:
TranslationResult: The translation result as a dictionary.
"""

# Create the URL for the API endpoint
url: str = self.create_api_endpoint(f"translation_result/{run_id}")

# Send a GET request to the API endpoint and get the response
response: requests.Response = self.session.get(url)

if response.status_code != 200:
print("Error: There was an error with your GET request.")
return response.json()

# If save_to_file is True, write the translation result to a file
if save_to_file:
# text_to_write = response.json()
with open(f"translation_result_{run_id}.txt", "w", encoding="utf-8") as file:
file.writelines([
"Camb AI Translation Result\n",
Expand Down

0 comments on commit f648f5e

Please sign in to comment.