()
| 61 | |
| 62 | |
| 63 | def main(): |
| 64 | # Create a parser, reusing most of the arguments from the main CLI |
| 65 | parser = get_parser(prog_name=None) |
| 66 | args = parser.parse_args() |
| 67 | auth_key = args.auth_key or os.getenv(env_auth_key) |
| 68 | server_url = args.server_url or os.getenv(env_server_url) |
| 69 | if auth_key is None: |
| 70 | raise Exception( |
| 71 | f"Please provide authentication key via the {env_auth_key} " |
| 72 | "environment variable or --auth_key argument" |
| 73 | ) |
| 74 | |
| 75 | # Create a Translator object, and call get_usage() to validate connection |
| 76 | translator = deepl.Translator(auth_key, server_url=server_url) |
| 77 | translator.get_usage() |
| 78 | |
| 79 | for json in args.json: |
| 80 | output = translate_json( |
| 81 | json, |
| 82 | translator=translator, |
| 83 | source_lang=args.source_lang, |
| 84 | target_lang=args.target_lang, |
| 85 | ) |
| 86 | print(output) |
| 87 | |
| 88 | |
| 89 | if __name__ == "__main__": |
no test coverage detected