def create_precinct_splits(w, cursor, config): print "Creating precinct split elements..." mem = Datastore(":memory:") c = mem.connect() c.execute( """CREATE TABLE IF NOT EXISTS Split_Polling ( polling_location_id INTEGER, split_id INTEGER, PRIMARY KEY(polling_location_id, split_id) )""" ) cursor.execute( """SELECT polling_location_id AS polling_location_id, split_id AS precinct_split_id FROM Split_Polling""" ) for row in cursor: c.execute("INSERT INTO Split_Polling VALUES (?,?)", (list(row))) mem.commit() cursor.execute( """SELECT ps.id AS original_id, ?||ps.id AS id, ps.name, mail_only, ?||precinct_id AS precinct_id FROM Precinct_Split ps, Precinct p WHERE p.id=ps.precinct_id""", (config.get("Precinct_Split", "split_prefix"), config.get("Precinct", "precinct_prefix")), ) for row in cursor: root = ET.Element("precinct_split", id=unicode(row["id"])) name = ET.SubElement(root, "name") name.text = row["name"] precinct_id = ET.SubElement(root, "precinct_id") precinct_id.text = unicode(row["precinct_id"]) if row["mail_only"] is not None and len(row["mail_only"]) > 0: if row["mail_only"] == "Yes": w.write(ET.tostring(root)) continue else: c.execute( """SELECT ?||polling_location_id AS polling_location_id FROM Split_Polling WHERE split_id=?""", (config.get("Polling_Location", "polling_prefix"), row["original_id"]), ) for p in c: polling_location_id = ET.SubElement(root, "polling_location_id") polling_location_id.text = unicode(p["polling_location_id"]) w.write(ET.tostring(root))
def create_precinct_splits(w, cursor, config): print "Creating precinct split elements..." mem = Datastore(':memory:') c = mem.connect() c.execute("""CREATE TABLE IF NOT EXISTS Split_Polling ( polling_location_id INTEGER, split_id INTEGER, PRIMARY KEY(polling_location_id, split_id) )""") cursor.execute("""SELECT polling_location_id AS polling_location_id, split_id AS precinct_split_id FROM Split_Polling""") for row in cursor: c.execute("INSERT INTO Split_Polling VALUES (?,?)", (list(row))) mem.commit() cursor.execute( """SELECT ps.id AS original_id, ?||ps.id AS id, ps.name, mail_only, ?||precinct_id AS precinct_id FROM Precinct_Split ps, Precinct p WHERE p.id=ps.precinct_id""", ( config.get('Precinct_Split', 'split_prefix'), config.get('Precinct', 'precinct_prefix'), )) for row in cursor: root = ET.Element("precinct_split", id=unicode(row['id'])) name = ET.SubElement(root, "name") name.text = row['name'] precinct_id = ET.SubElement(root, "precinct_id") precinct_id.text = unicode(row['precinct_id']) if row['mail_only'] is not None and len(row['mail_only']) > 0: if row['mail_only'] == 'Yes': w.write(ET.tostring(root)) continue else: c.execute( """SELECT ?||polling_location_id AS polling_location_id FROM Split_Polling WHERE split_id=?""", ( config.get('Polling_Location', 'polling_prefix'), row['original_id'], )) for p in c: polling_location_id = ET.SubElement( root, "polling_location_id") polling_location_id.text = unicode( p['polling_location_id']) w.write(ET.tostring(root))
def create_precincts(w, cursor, config): """Writes all election administration information""" print "Creating precinct elements..." mem = Datastore(":memory:") c = mem.connect() c.execute( """CREATE TABLE IF NOT EXISTS Precinct_Polling ( polling_location_id INTEGER, precinct_id INTEGER, PRIMARY KEY(polling_location_id, precinct_id) )""" ) cursor.execute( """SELECT polling_location_id AS polling_location_id, precinct_id AS precinct_id FROM Precinct_Polling""" ) for row in cursor: c.execute("INSERT INTO Precinct_Polling VALUES (?,?)", (list(row))) mem.commit() cursor.execute( """SELECT P.id AS original_id, ?||P.id AS id, P.name, ?||P.locality_id AS locality_id, P.mail_only FROM Precinct P, Locality L WHERE P.locality_id = L.id AND P.locality_id IS NOT NULL AND P.name IS NOT NULL""", (config.get("Precinct", "precinct_prefix"), config.get("Locality", "locality_prefix")), ) for row in cursor: root = ET.Element("precinct", id=unicode(row["id"])) name = ET.SubElement(root, "name") name.text = row["name"] locality_id = ET.SubElement(root, "locality_id") locality_id.text = unicode(row["locality_id"]) if row["mail_only"] is not None and len(row["mail_only"]) > 0: mail_only = ET.SubElement(root, "mail_only") mail_only.text = row["mail_only"] if row["mail_only"] == "Yes": w.write(ET.tostring(root)) continue else: c.execute( """SELECT ?||polling_location_id AS polling_location_id FROM Precinct_Polling WHERE precinct_id=?""", (config.get("Polling_Location", "polling_prefix"), row["original_id"]), ) for p in c: polling_location_id = ET.SubElement(root, "polling_location_id") polling_location_id.text = unicode(p["polling_location_id"]) w.write(ET.tostring(root))
def create_precincts(w, cursor, config): """Writes all election administration information""" print "Creating precinct elements..." mem = Datastore(':memory:') c = mem.connect() c.execute("""CREATE TABLE IF NOT EXISTS Precinct_Polling ( polling_location_id INTEGER, precinct_id INTEGER, PRIMARY KEY(polling_location_id, precinct_id) )""") cursor.execute("""SELECT polling_location_id AS polling_location_id, precinct_id AS precinct_id FROM Precinct_Polling""") for row in cursor: c.execute("INSERT INTO Precinct_Polling VALUES (?,?)", (list(row))) mem.commit() cursor.execute( """SELECT P.id AS original_id, ?||P.id AS id, P.name, ?||P.locality_id AS locality_id, P.mail_only FROM Precinct P, Locality L WHERE P.locality_id = L.id AND P.locality_id IS NOT NULL AND P.name IS NOT NULL""", ( config.get('Precinct', 'precinct_prefix'), config.get('Locality', 'locality_prefix'), )) for row in cursor: root = ET.Element("precinct", id=unicode(row['id'])) name = ET.SubElement(root, "name") name.text = row['name'] locality_id = ET.SubElement(root, "locality_id") locality_id.text = unicode(row['locality_id']) if row['mail_only'] is not None and len(row['mail_only']) > 0: mail_only = ET.SubElement(root, "mail_only") mail_only.text = row['mail_only'] if row['mail_only'] == 'Yes': w.write(ET.tostring(root)) continue else: c.execute( """SELECT ?||polling_location_id AS polling_location_id FROM Precinct_Polling WHERE precinct_id=?""", ( config.get('Polling_Location', 'polling_prefix'), row['original_id'], )) for p in c: polling_location_id = ET.SubElement( root, "polling_location_id") polling_location_id.text = unicode( p['polling_location_id']) w.write(ET.tostring(root))