Skip to content

Commit 95d090d

Browse files
authored
Update BreakSentence.py
1 parent 6a1ebf0 commit 95d090d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

BreakSentence.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@
77
# You may need to install requests and uuid.
88
# Run: pip install requests uuid
99

10-
1110
import os, requests, uuid, json
1211

13-
# Checks to see if the Translator Text subscription key is available
14-
# as an environment variable. If you are setting your subscription key as a
15-
# string, then comment these lines out.
16-
if 'TRANSLATOR_TEXT_KEY' in os.environ:
17-
subscriptionKey = os.environ['TRANSLATOR_TEXT_KEY']
18-
else:
19-
print('Environment variable for TRANSLATOR_TEXT_KEY is not set.')
20-
exit()
21-
# If you want to set your subscription key as a string, uncomment the next line.
22-
#subscriptionKey = 'put_your_key_here'
12+
key_var_name = 'TRANSLATOR_TEXT_SUBSCRIPTION_KEY'
13+
if not key_var_name in os.environ:
14+
raise Exception('Please set/export the environment variable: {}'.format(key_var_name))
15+
subscriptionKey = os.environ[key_var_name]
16+
17+
endpoint_var_name = 'TRANSLATOR_TEXT_ENDPOINT'
18+
if not endpoint_var_name in os.environ:
19+
raise Exception('Please set/export the environment variable: {}'.format(endpoint_var_name))
20+
endpoint = os.environ[endpoint_var_name]
2321

2422
# If you encounter any issues with the base_url or path, make sure
2523
# that you are using the latest endpoint: https://docs.microsoft.com/azure/cognitive-services/translator/reference/v3-0-break-sentence
26-
base_url = 'https://api.cognitive.microsofttranslator.com'
2724
path = '/breaksentence?api-version=3.0'
2825
params = '&language=en'
29-
constructed_url = base_url + path + params
26+
constructed_url = endpoint + path + params
3027

3128
headers = {
3229
'Ocp-Apim-Subscription-Key': subscriptionKey,

0 commit comments

Comments
 (0)