Skip to content

Commit 46cd1c7

Browse files
author
Chris Park
committed
RCB-357 Updated script to detect exceptions, Version to 1.0, Removed CHANGES.txt, Fixed name_translation Transliteration Scheme error
1 parent a373202 commit 46cd1c7

File tree

7 files changed

+64
-41
lines changed

7 files changed

+64
-41
lines changed

CHANGES.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include README.md CHANGES.txt LICENSE.txt
1+
include README.md LICENSE.txt
22
exclude MANIFEST.in

docker/run_python.sh

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
22

3+
retcode=0
4+
ping_url="https://api.rosette.com/rest/v1"
5+
6+
#------------------ Functions ----------------------------------------------------
37
#Gets called when the user doesn't provide any args
48
function HELP {
59
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
@@ -12,6 +16,54 @@ function HELP {
1216
exit 1
1317
}
1418

19+
#Checks if Rosette API key is valid
20+
function checkAPI {
21+
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
22+
if [ ! -z $match ]; then
23+
echo -e "\nInvalid Rosette API Key"
24+
exit 1
25+
fi
26+
}
27+
28+
function cleanURL() {
29+
# strip the trailing slash off of the alt_url if necessary
30+
if [ ! -z "${ALT_URL}" ]; then
31+
case ${ALT_URL} in
32+
*/) ALT_URL=${ALT_URL::-1}
33+
echo "Slash detected"
34+
;;
35+
esac
36+
ping_url=${ALT_URL}
37+
fi
38+
}
39+
40+
function validateURL() {
41+
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API")
42+
if [ "${match}" = "" ]; then
43+
echo -e "\n${ping_url} server not responding\n"
44+
exit 1
45+
fi
46+
}
47+
48+
function runExample() {
49+
echo -e "\n---------- ${1} start -------------"
50+
result=""
51+
if [ -z ${ALT_URL} ]; then
52+
result="$(python ${1} --key ${API_KEY} 2>&1 )"
53+
else
54+
result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )"
55+
fi
56+
echo "${result}"
57+
echo -e "\n---------- ${1} end -------------"
58+
if [[ "${result}" == *"Exception"* ]]; then
59+
echo "Exception found"
60+
retcode=1
61+
elif [[ "$result" == *"processingFailure"* ]]; then
62+
retcode=1
63+
fi
64+
}
65+
#------------------ Functions End ------------------------------------------------
66+
1567
#Gets API_KEY, FILENAME and ALT_URL if present
1668
while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
1769
case "${arg}" in
@@ -37,33 +89,11 @@ while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
3789
;;
3890
esac
3991
done
40-
ping_url="https://api.rosette.com/rest/v1"
4192

42-
# strip the trailing slash off of the alt_url if necessary
43-
if [ ! -z "${ALT_URL}" ]; then
44-
case ${ALT_URL} in
45-
*/) ALT_URL=${ALT_URL::-1}
46-
echo "Slash detected"
47-
;;
48-
esac
49-
ping_url=${ALT_URL}
50-
fi
93+
cleanURL
5194

52-
#Checks for valid url
53-
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API")
54-
if [ "${match}" = "" ]; then
55-
echo -e "\n${ping_url} server not responding\n"
56-
exit 1
57-
fi
95+
validateURL
5896

59-
#Checks if Rosette API key is valid
60-
function checkAPI {
61-
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
62-
if [ ! -z $match ]; then
63-
echo -e "\nInvalid Rosette API Key"
64-
exit 1
65-
fi
66-
}
6797

6898
#Copy the mounted content in /source to current WORKDIR
6999
cp -r -n /source/* .
@@ -75,15 +105,11 @@ if [ ! -z ${API_KEY} ]; then
75105
python /python-dev/setup.py install
76106
cd /python-dev/examples
77107
if [ ! -z ${FILENAME} ]; then
78-
if [ ! -z ${ALT_URL} ]; then
79-
python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
80-
else
81-
python ${FILENAME} --key ${API_KEY}
82-
fi
108+
runExample ${FILENAME}
83109
elif [ ! -z ${ALT_URL} ]; then
84-
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \;
85-
else
86-
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \;
110+
for file in *.py; do
111+
runExample ${file}
112+
done
87113
fi
88114
else
89115
HELP
@@ -109,3 +135,5 @@ if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
109135
git commit -a -m "publish python apidocs ${VERSION}"
110136
git push
111137
fi
138+
139+
exit ${retcode}

examples/name_translation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def run(key, altUrl='https://api.rosette.com/rest/v1/'):
2121
params["entityType"] = "PERSON"
2222
params["targetLanguage"] = "eng"
2323
params["targetScript"] = "Latn"
24-
params["targetScheme"] = "IC"
2524
return api.name_translation(params)
2625

2726

rosette/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
limitations under the License.
1717
"""
1818

19-
__version__ = '0.8.0'
19+
__version__ = '1.0'

rosette/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from datetime import datetime
3030
import requests
3131

32-
_BINDING_VERSION = "0.10"
32+
_BINDING_VERSION = "1.0"
3333
_GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08])
3434
N_RETRIES = 3
3535
HTTP_CONNECTION = None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def read(*filenames, **kwargs):
2323
buf.append(f.read())
2424
return sep.join(buf)
2525

26-
long_description = read('README.md', 'CHANGES.txt')
26+
long_description = read('README.md')
2727

2828
setup(name=NAME,
2929
author=AUTHOR,

0 commit comments

Comments
 (0)