summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2013-01-21 13:04:37 +0200
committerYuval Adam <yuv.adm@gmail.com>2013-01-21 13:04:37 +0200
commitb14e3395644c6b8d649a4a81718aad0fafe5b4e3 (patch)
tree61d7d1a8cf843ba72a3684762c732bf6d483eecb
parenta3c05b46f15ef5aba49fa30d6380aaa34012431f (diff)
Initial regex for ballot extractionHEADmaster
-rw-r--r--ballots.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/ballots.py b/ballots.py
new file mode 100644
index 0000000..d822d84
--- /dev/null
+++ b/ballots.py
@@ -0,0 +1,17 @@
+import re
+
+def read_file(filename):
+ with open(filename, 'r') as f:
+ return f.read()
+
+def get_ballots(f):
+ BALLOT_DATA_RE = re.compile(
+ r'(\d\d)\n(.*)\n(\d\d\d\d)\n(.*)\n([\d\.]+)\n(.*)\n(.*)')
+ m = re.findall(BALLOT_DATA_RE, f)
+ for x in m:
+ commitee_id, commitee, city_id, city, ballot_id, ballot_address, ballot_location = x
+ print commitee_id, commitee, city_id, city, ballot_id, ballot_address, ballot_location
+
+f = read_file('ballots.txt')
+data = get_ballots(f)
+print data