Owen Stephens
By: a guest | Mar 20th, 2010 | Syntax:
Python | Size: 0.88 KB | Hits: 67 | Expires: Never
from __future__ import print_function
import urllib
import httplib
import sys
import re
if len(sys.argv) != 2:
print("Please enter latex source file name to POST.", file=sys.stderr)
exit()
input_file_name = sys.argv[1]
input_file = open(input_file_name)
input = input_file.read()
params = urllib.urlencode({'latexcode': input})
headers = {"Content-type": "application/x-www-form-urlencoded"}
conn = httplib.HTTPConnection("dna.uio.no:80")
conn.request("POST", "/cgi-bin/texcount/texcount_2_2.cgi", params, headers)
response = conn.getresponse()
if response:
data = response.read()
match = re.search("<dt>Words\s+in\s+text:\s+</dt>\s*<dd>(\d+)", data)
if match is not None:
print("Count: " + match.group(1))
else:
print("Error parsing response.",file=sys.stderr)
else:
print("Error POSTing.", file=sys.stderr)