Skip to content

Instantly share code, notes, and snippets.

@catalin-hritcu
Created September 13, 2019 11:20
Show Gist options
  • Save catalin-hritcu/dc629268f50211bd9eb722be122188fc to your computer and use it in GitHub Desktop.
Save catalin-hritcu/dc629268f50211bd9eb722be122188fc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from zeus import core
def load_file(file_name):
fd = open(file_name, "r")
data = core.from_canonical(fd)
fd.close()
return data
def extract_name(name):
i = len(name)-1
while name[i] != '<':
i = i - 1
i = i -1
while name[i] == ' ':
i = i - 1
i = i + 1
if name[0] == ' ':
return name[1:i]
else:
return name[:i]
def extract_names(data, output_name):
f = open(output_name, "w")
for voterid in data["voters"]:
f.write(extract_name(data["voters"][voterid][0]))
f.write('\n')
def extract_names_from_all(f1, f2, f3):
extract_names(f1, "./cabina-1-lista-membri.txt")
extract_names(f2, "./cabina-2-lista-membri.txt")
extract_names(f3, "./cabina-3-lista-membri.txt")
def extract_voters_names(data, output_name):
f = open(output_name, "w")
ids = list(map(lambda x: x.get("voter"), data["votes"]))
for voterid in data["voters"]:
if voterid in ids:
f.write(extract_name(data["voters"][voterid][0]))
f.write('\n')
f.close()
def extract_voters_names_from_all(f1, f2, f3):
extract_voters_names(f1, "./cabina-1-lista-votanti.txt")
extract_voters_names(f2, "./cabina-2-lista-votanti.txt")
extract_voters_names(f3, "./cabina-3-lista-votanti.txt")
def extract_complete_list(data, cabin, f):
l = []
for voterid in data["voters"]:
v = dict()
v["name"] = extract_name(data["voters"][voterid][0])
v["id"] = voterid
v["cabina"] = str(cabin)
if voterid in data["cast_votes"]:
x = len(data["cast_votes"][voterid])
v["voturi"] = str(x)
v["last_sign"] = data["cast_votes"][voterid][x-1]
else:
v["voturi"] = '0'
l.append(v)
return l
def print_list(f, l):
f.write('<ul>\n')
for v in l:
f.write('<li>\n')
f.write('<div class="tooltip"><b>')
if len(v["name"]) == 0:
f.write(v["id"])
else:
f.write(v["name"])
f.write('<span class="tooltiptext">')
f.write(v["id"])
f.write('</span>')
f.write('</b></div>, cabina ')
f.write(v["cabina"])
f.write(', voturi ')
f.write(v["voturi"])
if v["voturi"] != '0':
f.write(', <a href="./signatures/')
f.write(v["last_sign"])
f.write('">ultima chitanta</a>\n')
f.write('</li>\n')
f.write('</ul>\n')
def extract_complete_list_all(f1, f2, f3):
f = open("./index.html", "w")
f.write("""
<!DOCTYPE html>
<html>
<head>
<title>Lista alegeri pentru presedentia USR, septembrie 2019</title>
</head>
<meta charset="UTF-8">
<style>
/* Tooltip container */
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}
/* Tooltip text */
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
padding: 5px 0;
border-radius: 6px;
/* Position the tooltip text - see examples below! */
position: absolute;
z-index: 1;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
<body>""")
l = extract_complete_list(f1, 1, f)
l += extract_complete_list(f2, 2, f)
l += extract_complete_list(f3, 3, f)
l.sort(key = lambda x: x["name"].lower())
print_list(f, l)
f.write('</body></html>')
f.close()
def compara_registre_cu_liste(registru_votanti_n, lista_votanti_n):
registru_votanti_f = open(registru_votanti_n, "r")
registru_votanti = registru_votanti_f.read().split("\n")
lista_votanti_f = open(lista_votanti_n, "r")
lista_votanti = lista_votanti_f.read().split("\n")
print("In registru, si nu in lista")
print(len(set(registru_votanti).difference(set(lista_votanti))))
print(set(registru_votanti).difference(set(lista_votanti)))
print("In lista, si nu in registru")
print(len(set(lista_votanti).difference(set(registru_votanti))))
print(set(lista_votanti).difference(set(registru_votanti)))
print("\n\n")
f1 = load_file("./cabina-1-de-vot_proofs.txt")
f2 = load_file("./cabina-2-de-vot_proofs.txt")
f3 = load_file("./cabina-3-de-vot_proofs.txt")
extract_complete_list_all(f1, f2, f3)
#extract_voters_names_from_all(f1, f2, f3)
#compara_registre_cu_liste('./cabina-1-registru-votanti.csv', './cabina-1-lista-votanti.txt')
#compara_registre_cu_liste('./cabina-2-registru-votanti.csv', './cabina-2-lista-votanti.txt')
#compara_registre_cu_liste('./cabina-3-registru-votanti.csv', './cabina-3-lista-votanti.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment