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
/
crear_asignacion.py
executable file
·103 lines (84 loc) · 2.51 KB
/
crear_asignacion.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
#!/usr/bin/env python3
import os
import re
import sys
from datetime import datetime
import requests
import xlrd
from api import (Descripciones, Jnj2, Organismo, Puesto, dict_from_txt,
get_cod_dir_latlon, get_direcciones_txt, money,
simplificar_dire, soup_from_file, yaml_from_file)
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
re_etiqueta = re.compile(r"^(\S+)\s+\[(\d+),\s*(\d+)\]\s*$")
re_space = re.compile(r" +")
re_number = re.compile(r"^\d+,\d+$")
if not os.path.isfile(".ig_leer_puestos"):
sys.exit("Ha de crear un fichero .ig_leer_puestos")
def parse(cell, parse_number=True):
if not cell:
return None
v = cell.value
if isinstance(v, float):
return int(v) if v.is_integer() else v
if isinstance(v, str):
v = v.strip()
v = re_space.sub(" ", v)
if parse_number and re_number.match(v):
v = float(v.replace(",", "."))
return int(v) if v.is_integer() else v
return v if len(v) else None
return v
puestos = Puesto.load(name="2017_L")
unidades = {p.ranking: p.idUnidad for p in puestos}
url = None
with open(".ig_leer_puestos") as f:
lineas = [l.strip() for l in f.readlines() if l.strip()]
url = lineas[0]
def get_ok_index(idUnidad, *arg):
last_unidad = None
index = 0
for a in arg:
unidad = unidades[a]
if last_unidad is None or unidad != last_unidad:
last_unidad = unidad
index = index + 1
if unidad == idUnidad:
return index
return -1
def contar(*arg):
i = 0
for a in arg:
if a is None:
return i
i = i + 1
return i
r = requests.get(url+"&raw=1")
wb = xlrd.open_workbook(file_contents=r.content)
sh = wb.sheet_by_index(2)
renuncias = 0
opositores = 0
oks = {}
for rx in range(1, sh.nrows):
row = [parse(c) for c in sh.row(rx)]
asignacion = row[1]
if asignacion is None or asignacion < 1:
continue
if asignacion > 1000:
renuncias = renuncias + 1
continue
peticion = [abs(int(i))
for i in row[3:] if i is not None and abs(int(i)) != 0]
opositores = opositores + 1
unidad = unidades[asignacion]
index = get_ok_index(unidad, *peticion)
ok = oks.get(index, 0) + 1
oks[index] = ok
j2 = Jnj2("j2/", "docs/")
j2.save("asignacion.html",
oks=oks,
now=datetime.now().strftime("%d-%m-%Y %H:%M"),
opositores=opositores,
renuncias=renuncias
)