This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcrear_htmls.py
executable file
·133 lines (109 loc) · 4.33 KB
/
crear_htmls.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import bs4
from api import Descripciones, Info, Jnj2, Organismo, Puesto, fix_html
parser = argparse.ArgumentParser(
description='Crea el portal html')
parser.add_argument('--todo', action='store_true', help='Autoexplicativo')
parser.add_argument('--direcciones', action='store_true',
help='Solo genera la parte de las direcciones')
parser.add_argument(
'--destinos', action='store_true', help='Solo genera la parte de destinos')
parser.add_argument(
'--ranking', action='store_true', help='Solo genera la parte del ranking')
args = parser.parse_args()
j2 = Jnj2("j2/", "docs/")
# Excluir CENTROS PENITENCIARIOS, y volver a comprobar que es TAI
# Excluir nivel 18 (puede que salta alguno pero serán tan pocos...)
todos_tai = [p for p in Puesto.load() if p.idCentroDirectivo !=
1301 and p.idProvision not in ("L",) and p.isTAI()]
todos_19 = [p for p in todos_tai if p.nivel < 19]
descripciones = Descripciones.load()
organismos = {}
for o in Organismo.load():
for c in o.codigos:
organismos[c] = o
if args.todo or args.direcciones:
nf = Info(todos_tai, descripciones, organismos)
j2.save("direcciones.html", info=nf, parse=fix_html)
if args.todo or args.destinos:
paths = []
for pais in set([p.pais for p in todos_19]):
for provincia in set([p.provincia for p in todos_19 if p.pais == pais]):
puestos = [p for p in todos_19 if p.pais ==
pais and p.provincia == provincia]
path = "%03d/%02d/index.html" % (pais or "XXX", provincia or "XXX")
nf = Info(puestos, descripciones, organismos)
j2.save("table.html", destino=path, info=nf, parse=fix_html)
paths.append((nf.deProvincia, path, len(
[p for p in puestos if p.estado == "V"])))
total_vacantes = len([p for p in todos_19 if p.estado == "V"])
paths = sorted(paths)
j2.save("destinos.html", paths=paths, total_vacantes=total_vacantes)
if args.todo or args.ranking:
convocatorias = (
(2016, 'L', 'BOE-A-2018-991', []),
(2015, 'L', 'BOE-A-2016-12467', []),
)
descripciones = Descripciones.load().__dict__
puestos = {str(p.idPuesto): p for p in Puesto.load()}
claves = ("idMinisterio", "idCentroDirectivo", "idUnidad")
ofertas = {}
for year, tipo, nombramientos, destinos in convocatorias:
destinos.extend(Puesto.load(name=("%s_%s" % (year, tipo))))
destinos.sort(key=lambda p: p.ranking)
for p in destinos:
for k in claves:
dc = ofertas.get(k, {})
vl = p.__dict__.get(k, None)
if vl:
conv = dc.get(vl, set())
conv.add(year)
dc[vl] = conv
ofertas[k] = dc
def get_ranking(provincia, destinos, pieza, campo):
destinos = [d for d in destinos if d.provincia == provincia]
if pieza > 0:
destinos = destinos[:pieza]
else:
destinos = destinos[pieza:]
info = {}
for d in destinos:
valor = d.__dict__[campo]
if valor:
count, rank = info.get(valor, (0, []))
rank.append(d.ranking)
info[valor] = (count + 1, rank)
k = campo[2:]
k = k[0].lower() + k[1:]
desc = descripciones[k]
info = [(i[0], desc[str(i[0])], i[1][0], i[1][1] if pieza >
0 else list(reversed(i[1][1]))) for i in info.items()]
info = sorted(info, key=lambda i: (-i[2], i[3]))
return info
pieza = 15
ranking = {}
for year, _, _, destinos in convocatorias:
ranking[year] = {}
for k in claves:
ranking[year][k] = {}
ranking[year][k]["arriba"] = get_ranking(28, destinos, +pieza, k)
ranking[year][k]["abajo"] = get_ranking(28, destinos, -pieza, k)
j2 = Jnj2("j2/", "docs/")
j2.save(
"ranking.html",
convocatorias=convocatorias,
ranking=ranking,
textos={
"idMinisterio": "Ministerio",
"idCentroDirectivo": "Centro directivo",
"idUnidad": "Unidad"
},
claves=claves,
pieza=pieza,
ofertas=ofertas,
parse=fix_html
)
j2.save("index.html")
j2.save("asignacion.html")