Difference between revisions of "Batch Results Retrieval in Python3"
From Textserver wiki
(No difference)
|
Latest revision as of 10:33, 24 August 2018
1 #!/usr/bin/env python3
2
3 import requests
4 import xml.etree.ElementTree
5
6 # set query elements
7 user = raw_input('TextServer Username: ')
8 tkid = raw_input('TextServer Job Token ID: ')
9 outfname = raw_input('Output ZIP file: ')
10
11 # Create request
12 request_data = {'username' : user
13 'tokenID' : tkid
14 }
15
16 # service URL
17 url = "http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws/resultRetrieve"
18
19 # Send request and get response
20 resp = requests.post(url, files=request_data)
21
22 # HTTP error, raise exception
23 if resp.status_code != requests.codes.ok :
24 resp.raise_for_status()
25
26 # no error, save results to output file
27 outf=open(outfname, 'w+')
28 print(resp, file=outf)
29 outf.close()
30 print "Job finished. Results saved to",outfname