Difference between revisions of "Batch Results Retrieval in curl"
From Textserver wiki
(Created page with "<syntaxhighlight lang="bash" line="1" > </syntaxhighlight>") |
|||
Line 1: | Line 1: | ||
<syntaxhighlight lang="bash" line="1" > | <syntaxhighlight lang="bash" line="1" > | ||
+ | #! /bin/sh | ||
+ | |||
+ | ######################################################################## | ||
+ | # | ||
+ | # Example client to retrieve results for a batch job previously submitted | ||
+ | # | ||
+ | # Output will be a ZIP file containing results for each input file in | ||
+ | # the requested format (XML, json, conll) | ||
+ | # | ||
+ | ######################################################################## | ||
+ | |||
+ | # Get query parameters | ||
+ | echo -n "TextServer username: " | ||
+ | read USERNAME | ||
+ | echo -n "TextServer Job Token ID: " | ||
+ | read TKID | ||
+ | echo -n "Output ZIP file: " | ||
+ | read OUTFNAME | ||
+ | |||
+ | TEXTSERVER_URL="http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws" | ||
+ | |||
+ | echo "Polling server for job completion..." | ||
+ | curl -X POST -s -S \ | ||
+ | --form "username=$USERNAME" \ | ||
+ | --form "tokenID=$TKID" \ | ||
+ | $TEXTSERVER_URL"/resultRetrieve" >$OUTFNAME | ||
+ | |||
+ | if ( grep -q '\[TS-125\]' $OUTFNAME ); then | ||
+ | # server returned HTTP 503, with TextSErver code [TS-125], which means job not finished | ||
+ | echo "Job not finished yet" | ||
+ | rm $OUTFNAME | ||
+ | exit | ||
+ | elif ( grep -q '\[TS-' $OUTFNAME ); then | ||
+ | # some other error from TextServer | ||
+ | cat $OUTFNAME | ||
+ | echo "" | ||
+ | rm $OUTFNAME | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | # no error, we got the results. | ||
+ | echo "Job finished. Results saved to "$OUTFNAME | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 12:29, 21 January 2016
1 #! /bin/sh
2
3 ########################################################################
4 #
5 # Example client to retrieve results for a batch job previously submitted
6 #
7 # Output will be a ZIP file containing results for each input file in
8 # the requested format (XML, json, conll)
9 #
10 ########################################################################
11
12 # Get query parameters
13 echo -n "TextServer username: "
14 read USERNAME
15 echo -n "TextServer Job Token ID: "
16 read TKID
17 echo -n "Output ZIP file: "
18 read OUTFNAME
19
20 TEXTSERVER_URL="http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws"
21
22 echo "Polling server for job completion..."
23 curl -X POST -s -S \
24 --form "username=$USERNAME" \
25 --form "tokenID=$TKID" \
26 $TEXTSERVER_URL"/resultRetrieve" >$OUTFNAME
27
28 if ( grep -q '\[TS-125\]' $OUTFNAME ); then
29 # server returned HTTP 503, with TextSErver code [TS-125], which means job not finished
30 echo "Job not finished yet"
31 rm $OUTFNAME
32 exit
33 elif ( grep -q '\[TS-' $OUTFNAME ); then
34 # some other error from TextServer
35 cat $OUTFNAME
36 echo ""
37 rm $OUTFNAME
38 exit
39 fi
40
41 # no error, we got the results.
42 echo "Job finished. Results saved to "$OUTFNAME