# HG changeset patch # User Paul Boddie # Date 1383415417 -3600 # Node ID 92a814314fdaa7fd416683a36843cb9a52a7f33b # Parent 23a3195da608e213c5a17a94091076ba8bd8d935 Attempted to make the tools handle non-ASCII characters properly. diff -r 23a3195da608 -r 92a814314fda tools/addusers.py --- a/tools/addusers.py Sat Nov 02 01:48:34 2013 +0100 +++ b/tools/addusers.py Sat Nov 02 19:03:37 2013 +0100 @@ -18,6 +18,7 @@ from subprocess import call import random, string import sys +import codecs def randompass(): return "".join(random.sample(string.ascii_letters, 10)) @@ -41,14 +42,16 @@ print >>sys.stderr, "Example: %s wiki" % progname sys.exit(1) - line = sys.stdin.readline() + stdin = codecs.getreader("utf-8")(sys.stdin) + stdout = codecs.getwriter("utf-8")(sys.stdout) + line = stdin.readline() while line: username, fullname, email, image = line.strip("\n ").split("\t") password = randompass() add_user(wiki, username, fullname, email, password) - print "\t".join([username, fullname, email, image, password]) + print >>stdout, "\t".join([username, fullname, email, image, password]) - line = sys.stdin.readline() + line = stdin.readline() if __name__ == "__main__": main() diff -r 23a3195da608 -r 92a814314fda tools/get_profile.py --- a/tools/get_profile.py Sat Nov 02 01:48:34 2013 +0100 +++ b/tools/get_profile.py Sat Nov 02 19:03:37 2013 +0100 @@ -9,11 +9,11 @@ from os.path import split from urllib import basejoin -import libxml2dom, sys +import libxml2dom, sys, codecs def get_profile(url, username): try: - d = libxml2dom.parseURI("%s/display/~%s" % (url.rstrip("/"), username), html=True) + d = libxml2dom.parseURI("%s/display/~%s" % (url.rstrip("/"), username), html=True, htmlencoding="utf-8") fullname = d.xpath("//span[@id='fullName']") fullname = fullname and fullname[0].textContent or "" @@ -39,8 +39,9 @@ print >>sys.stderr, "Example: %s http://wiki.list.org/ " % progname sys.exit(1) + stdout = codecs.getwriter("utf-8")(sys.stdout) details = get_profile(url, username) - print "\t".join(details) + print >>stdout, "\t".join(details) if __name__ == "__main__": main() diff -r 23a3195da608 -r 92a814314fda tools/get_profiles.py --- a/tools/get_profiles.py Sat Nov 02 01:48:34 2013 +0100 +++ b/tools/get_profiles.py Sat Nov 02 19:03:37 2013 +0100 @@ -13,6 +13,7 @@ from time import sleep from os.path import split import sys +import codecs this_dir = split(sys.argv[0])[0] sys.path.append(this_dir) @@ -31,10 +32,11 @@ print >>sys.stderr, "Example: %s http://wiki.list.org/" % progname sys.exit(1) + stdout = codecs.getwriter("utf-8")(sys.stdout) line = sys.stdin.readline() while line: username = line.strip() - print "\t".join(get_profile(url, username)) + print >>stdout, "\t".join(get_profile(url, username)) sleep(delay) line = sys.stdin.readline()