Difference between revisions of "Curl Batch Client"

From Textserver wiki
Jump to: navigation, search
(Created page with "<syntaxhighlight lang="bash" line="1" > </syntaxhighlight>")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
<syntaxhighlight lang="bash" line="1" >
 
<syntaxhighlight lang="bash" line="1" >
 +
#! /bin/sh
 +
 +
########################################################################
 +
#
 +
#  Example client to submit a batch request to TextServer
 +
# SERVICENAME service, and wait for the job to be finished.
 +
#
 +
#  Input must be a ZIP file containing one or more text files to analyze
 +
#  Output will be a ZIP file containing results for each input file in
 +
# the requested format (XML, json, conll)
 +
#
 +
########################################################################
 +
 +
# Get query parameters
 +
echo -n "Input ZIP file: "
 +
read FNAME
 +
echo -n "Language: "
 +
read LANGUAGE
 +
echo -n "Output format (xml,json,conll,naf): "
 +
read OUT
 +
echo -n "TextServer username: "
 +
read USERNAME
 +
echo -n "TextServer password: "
 +
read PWD
 +
 +
TEXTSERVER_URL="http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws"
 +
# URL for the requested service
 +
SERVICE="SERVICENAME";
 +
 +
# send request to server, retrieve job token ID
 +
TEMPF=`mktemp -d`
 +
curl -X POST  \
 +
  --form "username=$USERNAME"  \
 +
  --form "password=$PWD"  \
 +
  --form "language=$LANGUAGE" \
 +
  --form "file=@$FNAME" \
 +
  --form "output=$OUT" \
 +
  --form "interactive=0" \
 +
  $TEXTSERVER_URL"/processQuery/"$SERVICE 2>/dev/null >tokenID.tmp
 +
 +
# check for TextServer error codes "[TS-XXX]" (invalid parameters, etc..)
 +
if ( grep -q '\[TS\-' tokenID.tmp ); then
 +
  cat tokenID.tmp
 +
  rm tokenID.tmp
 +
  exit
 +
fi
 +
 +
# extract job token id from response
 +
TOKENID=`cat tokenID.tmp | sed '/<job_token_id>/ ! D; /<job_token_id>/ s#<job_token_id>\(.*\)</job_token_id>#\1#'`
 +
rm tokenID.tmp
 +
echo "Job submitted. Token id="$TOKENID
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 12:04, 21 January 2016

 1 #! /bin/sh 
 2 
 3 ########################################################################
 4 #
 5 #  Example client to submit a batch request to TextServer 
 6 # SERVICENAME service, and wait for the job to be finished.
 7 #
 8 #  Input must be a ZIP file containing one or more text files to analyze
 9 #  Output will be a ZIP file containing results for each input file in
10 # the requested format (XML, json, conll)
11 #
12 ########################################################################
13 
14 # Get query parameters
15 echo -n "Input ZIP file: "
16 read FNAME
17 echo -n "Language: "
18 read LANGUAGE
19 echo -n "Output format (xml,json,conll,naf): "
20 read OUT
21 echo -n "TextServer username: "
22 read USERNAME
23 echo -n "TextServer password: "
24 read PWD
25 
26 TEXTSERVER_URL="http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws"
27 # URL for the requested service
28 SERVICE="SERVICENAME";
29 
30 # send request to server, retrieve job token ID
31 TEMPF=`mktemp -d`
32 curl -X POST  \
33    --form "username=$USERNAME"  \
34    --form "password=$PWD"  \
35    --form "language=$LANGUAGE" \
36    --form "file=@$FNAME" \
37    --form "output=$OUT" \
38    --form "interactive=0" \
39    $TEXTSERVER_URL"/processQuery/"$SERVICE 2>/dev/null >tokenID.tmp
40 
41 # check for TextServer error codes "[TS-XXX]" (invalid parameters, etc..)
42 if ( grep -q '\[TS\-' tokenID.tmp ); then
43   cat tokenID.tmp
44   rm tokenID.tmp
45   exit
46 fi
47 
48 # extract job token id from response
49 TOKENID=`cat tokenID.tmp | sed '/<job_token_id>/ ! D; /<job_token_id>/ s#<job_token_id>\(.*\)</job_token_id>#\1#'`
50 rm tokenID.tmp
51 echo "Job submitted. Token id="$TOKENID