Election Results

20 November, 2007

Here is a shell script to pull the two party preferred vote from the AEC. The data gets updated live every 90 seconds during elections. It requires ncftp and unzip.

An example run using election data from the 2004 election:

kared@minoc:~/election$ ./fetchxml.sh
LNP 54.02
ALP 45.98

# License: MIT http://www.opensource.org/licenses/mit-license.php
# Author: Jared Kells
#
# Simple shell script to pull the latest election results
# from the AEC, configure SERVER to the aec's ftp server
# set TRANS as the transaction ID.

SERVER=mediafeedtest.aec.gov.au
TRANS=13232
FILENAME=`ncftpls ftp://${SERVER}/${TRANS}/Standard/Verbose \
| tail -n 5 \
| head -n 1`

#Clean UP
rm data.xml
rm data.zip
rm -rf xml
rm -rf schema

#Fetch the zip file
ncftpget -VC ftp://${SERVER}/${TRANS}/Standard/Verbose/${FILENAME} \
data.zip 2>&1 > /dev/null

#Unzip
unzip -o data.zip 2>&1 > /dev/null

#Fetch XML file
cp xml/aec-mediafeed-results-standard-verbose-${TRANS}.xml ./data.xml \
2>&1 > /dev/null

#Parse, I only have 32MB Ram so shell xml_grep fails :(
cat data.xml | \
sed -n '/<\/Analysis/ p' | \
sed -n '/<\/National/ p' | \
sed -n '/<\/TwoPartyPreferred/ p' | \
awk '{FS="\""} /ShortCode=/ {printf "%s ", $4} /Votes/ { printf "%s\n", $2}'

Entry Filed under: Uncategorized. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Blogroll

Blog Stats

RSS US Forums