-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_table_deudores.py
More file actions
74 lines (51 loc) · 1.82 KB
/
make_table_deudores.py
File metadata and controls
74 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
import collections
import codecs
import operator
import sys
import locale
'''
Parsea archivo TSV de deudores y crea tabla en HTML.
'''
locale.setlocale(locale.LC_ALL, "en_US.utf8")
input_file = sys.argv[1].strip()
def to_number(string):
x = float(string)
return locale.format("%d", x, grouping=True)
# header
out = "<html><head><meta charset='utf-8'>"
out += "<link rel='stylesheet' href='bootstrap/css/bootstrap.min.css'>"
out += "<style>table { font-size: 10px; font-family: Verdana, Arial, serif; }</style>"
out += "</head>"
# table
out += u"<body>"
out += u"<div class='table-responsive'>"
out += u"<table class='table table-striped'><thead><tr>"
out += u"<th>Departamento</th><th>Provincia</th><th>Distrito</th>"
out += u"<th>Candidato</th><th>Partido político</th>"
out += u"<th>Cargo que postula</th>"
out += u"<th>Reparación Civil</th><th>Pagos Realizados</th>"
out += u"<th>Pagos Pendientes</th><th>Delito</th>"
out += u"</tr></thead><tbody>\n"
for line in codecs.open(input_file, "r", "utf-8").readlines():
line = line.strip()
if line.startswith("DNI"):
continue
line = line.split("\t")
out += "<td>" + line[5] + "</td>"
out += "<td>" + line[6].title() + "</td>"
out += "<td>" + line[7].title() + "</td>"
out += u"<td><a title='Link hacia página del MinJus' href='"
out += line[8] + "' target='_blank'>"
out += line[1].upper() + ", " + line[2].upper() + "</a></td>"
out += "<td>" + line[3] + "</td>"
out += "<td>" + line[4] + "</td>"
out += "<td>" + to_number(line[13]) + "</td>"
out += "<td>" + to_number(line[14]) + "</td>"
out += "<td>" + to_number(line[15]) + "</td>"
out += "<td>" + line[18][:33] + "</td>"
out += "</tr>\n"
out += "</tbody></table>"
out += "</div>"
out += "</body></html>"
print out.encode("utf-8")