User:Gadfium/scripts

Electorate.py
This is a python 3.x script which reads the 2011 New Zealand electorate result pages and outputs Wikipedia tables for the results.

To run it, use
 * python electorate.py [electorate number]

The output goes to a file named "Electorate-nn.txt"

The script has been modified minimally from a 2008 version. Most of the changes were required to run under python 3.x.

The interpreter used was python 3.2 under Windows 7. If you want a version which works under python 2.x, see the history of this page. Although I was a professional programmer in a past life, I've never worked professionally with Python and I don't know the language well. I tend to use it purely as a procedural language, although it has far more powerful concepts.

The Windows command prompt has trouble with Python producing the macron in the name of the Māori Party in its stdout stream. While it is possible to circumvent this using "SET PYTHONIOENCODING = UTF8" at the command prompt, it seems unreasonable to expect any potential end user of this program to do that, so I have written results directly to a file rather than to stdout as in previous versions. Candidates with accented characters in their names may still need adjustment. There is a crude method of converting candidate surnames to mixed case form, which mostly works for candidates with British-style names but fails for at least one Pacific Island candidate.

No attempt is made to add changes from the previous election. The script is only aware of the current results, not previous ones.

When run, it is necessary to fix the electorate name in the majority of cases, to match the Wikipedia naming of articles and to fix problems caused by macrons in names. It is also necessary to add the MMP election box majority hold or equivalent template at the end of the results, and to alter the incumbent template if the incumbent did not win the seat (ie, change MMP election box incumbent win to MMP election box candidate win and if the incumbent was a candidate, also change their template to MMP election box candidate lose

If adapting for similarly structured 2014 results, add parties with a list to the longPartyName structure, and parties with local candidates to the partyName structure. Parties with local candidates not added to partyName will cause this script to abort.

school.py
This is a python script which reads the wikitext from an article such as "List of schools in Southland, New Zealand" saved in the file "input.txt" and outputs boilerplate Wikipedia markup suitable for pasting into "Education" sections in the English and Māori wikipedia articles for the relevant locality or suburb. If there is more than one school in a given locality, the results should be hand-massaged to improve the flow of text. I generally try to add at least one more fact about each school anyway, most commonly the date of its founding.

The layout of the lists used as input is being changed as I complete each one, with one field being dropped and the order of the fields being changed. The newer format is not compatible with this script. The lists for Northland, Taranaki, Marlborough and West Coast are in the newer format.

To run it, use
 * python school.py > [text file]

This script is older than electorate.py above, but was modified to use TKI rather than hard-coding the equivalent references.