<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://textserver.lsi.upc.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Batch_Results_Retrieval_in_Python2</id>
		<title>Batch Results Retrieval in Python2 - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://textserver.lsi.upc.edu/wiki/index.php?action=history&amp;feed=atom&amp;title=Batch_Results_Retrieval_in_Python2"/>
		<link rel="alternate" type="text/html" href="http://textserver.lsi.upc.edu/wiki/index.php?title=Batch_Results_Retrieval_in_Python2&amp;action=history"/>
		<updated>2026-08-13T04:32:40Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://textserver.lsi.upc.edu/wiki/index.php?title=Batch_Results_Retrieval_in_Python2&amp;diff=161&amp;oldid=prev</id>
		<title>Padro: Created page with &quot;&lt;syntaxhighlight lang=&quot;python&quot; line=&quot;1&quot; &gt; #! /usr/bin/python  ######################################################################## # #  Example client to retrieve the resu...&quot;</title>
		<link rel="alternate" type="text/html" href="http://textserver.lsi.upc.edu/wiki/index.php?title=Batch_Results_Retrieval_in_Python2&amp;diff=161&amp;oldid=prev"/>
				<updated>2018-08-24T09:29:36Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot; &amp;gt; #! /usr/bin/python  ######################################################################## # #  Example client to retrieve the resu...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot; &amp;gt;&lt;br /&gt;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
########################################################################&lt;br /&gt;
#&lt;br /&gt;
#  Example client to retrieve the results of a batch request to TextServer &lt;br /&gt;
#&lt;br /&gt;
#  Output will be a ZIP file containing results for each input file in&lt;br /&gt;
# the requested format (XML, json, conll)&lt;br /&gt;
#&lt;br /&gt;
########################################################################&lt;br /&gt;
&lt;br /&gt;
# import required libraries&lt;br /&gt;
import urllib2&lt;br /&gt;
# You may need to install &amp;quot;poster&amp;quot; python module for these two:&lt;br /&gt;
from poster.encode import multipart_encode&lt;br /&gt;
from poster.streaminghttp import register_openers&lt;br /&gt;
import xml.etree.ElementTree&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
# Register the streaming http handlers with urllib2&lt;br /&gt;
register_openers()&lt;br /&gt;
&lt;br /&gt;
# set query elements&lt;br /&gt;
user = raw_input('TextServer Username: ')&lt;br /&gt;
tkid = raw_input('TextServer Job Token ID: ')&lt;br /&gt;
outfname = raw_input('Output ZIP file: ')&lt;br /&gt;
&lt;br /&gt;
# service URL&lt;br /&gt;
TextServer_URL = &amp;quot;http://frodo.lsi.upc.edu:8080/TextWS/textservlet/ws&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# prepare request to poll for completion and retrieve results&lt;br /&gt;
datagen, headers = multipart_encode({'username' : user,&lt;br /&gt;
                                     'tokenID' : tkid&lt;br /&gt;
                                     })&lt;br /&gt;
request = urllib2.Request(TextServer_URL + &amp;quot;/resultRetrieve&amp;quot;, &lt;br /&gt;
                          datagen, &lt;br /&gt;
                          headers)&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
  # send request to check for results&lt;br /&gt;
  print &amp;quot;Polling server for job completion...&amp;quot;&lt;br /&gt;
  resp =  urllib2.urlopen(request).read()&lt;br /&gt;
  &lt;br /&gt;
except urllib2.HTTPError, e:&lt;br /&gt;
  if (e.code == 503 and e.read()[0:8] == &amp;quot;[TS-125]&amp;quot; ) :&lt;br /&gt;
    # http status 503, textserver code TS-125 means the job is not finished yet. &lt;br /&gt;
    print &amp;quot;Job not finished yet&amp;quot; &lt;br /&gt;
  else :      &lt;br /&gt;
    # some actual error happened. abort&lt;br /&gt;
    print e, &amp;quot;-&amp;quot;, e.read()&lt;br /&gt;
  exit()&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
# no error, save results to output file&lt;br /&gt;
outf=open(outfname, 'w+')&lt;br /&gt;
print &amp;gt;&amp;gt;outf, resp&lt;br /&gt;
outf.close()&lt;br /&gt;
print &amp;quot;Job finished. Results saved to&amp;quot;,outfname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Padro</name></author>	</entry>

	</feed>