-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-auto-categoria.py
executable file
·141 lines (112 loc) · 4.38 KB
/
4-auto-categoria.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
134
135
136
137
138
139
140
141
#!/usr/bin/env python
import calendar
import configparser
import datetime
import os
import dateutil.parser
import common
config = configparser.ConfigParser()
config.read(os.path.expanduser("~/.avast.ini"))
token = common.gettoken(
user=config["auth"]["RWusername"], password=config["auth"]["RWpassword"]
)
headers = {"Authorization": f"Bearer {token}"}
# Definiciones
avast13 = 66
avast15 = 65
avast18 = 77
socioactivo = 82
# Periodicidad (bimensual: 5, anual: 3)
extras = {82: 3}
today = datetime.date.today()
# La cuota anual es el 20 de Febrero
if today.month < 2 or (today.month == 2 and today.day < 20):
fechacambiosocio = f"20/02/{today.year}"
else:
fechacambiosocio = f"20/02/{today.year+1}"
# Leer datos
socios = common.readjson("socios")
categorias = common.readjson("categorias")
today = datetime.date.today()
# Locate our member in the list of members
for socio in socios:
if (
"estat" in socio
and socio["estat"] == "COLESTVAL"
and "estatColegiat" in socio
and socio["estatColegiat"]["nom"] == "ESTALTA"
):
# ID Socio
socioid = int(socio["idColegiat"])
# Find our born year
try:
fecha = dateutil.parser.parse(socio["persona"]["dataNaixement"])
except Exception:
fecha = False
print(f"ERROR: Sin fecha nacimiento para socio ID: {socioid}")
if fecha:
year, month, day = fecha.year, fecha.month, fecha.day
categoriassocio = []
for categoria in socio["colegiatHasModalitats"]:
idcategoria = int(categoria["idModalitat"])
categoriassocio.append(idcategoria)
try:
myyear = int(categoria["modalitat"]["nom"])
except Exception:
myyear = False
if myyear:
if myyear != year:
print(f"ERROR: AÑO INCORRECTO para socio ID: {socioid}")
common.delcategoria(token, socioid, idcategoria)
targetcategorias = [socioactivo]
for categoria in categorias:
nombre = categoria["nom"]
# Attempt to find categories for a year
try:
mycat = int(nombre)
except Exception:
mycat = False
if mycat and mycat == year and year in range(2000, today.year):
# Our member had a match with the born year
targetcategorias.append(int(categoria["idModalitat"]))
fechadia = calendar.monthrange(today.year, today.month)[1]
edad = today.year - year - ((today.month, fechadia) < (month, day))
# Add target category for +13/+15
if edad in range(13, 15):
# AVAST+13
targetcategorias.append(avast13)
elif edad in range(15, 24):
# AVAST+15
targetcategorias.append(avast15)
# elif edad in range(18, 29):
# # AVAST+18
# targetcategorias.append(avast18)
# El socio no debe estar en grupos A+13 o A+15 o A+18
for i in [
avast13,
avast15,
]: # , avast18 #TODO Remove comment once avast18 is enabled
if i in categoriassocio and i not in targetcategorias:
print(f"ERROR: Borrando categoria {i} del socio {socioid}")
common.delcategoria(token, socioid, i)
for categoria in targetcategorias:
if categoria not in categoriassocio:
print(
"IFF",
socioid,
categoria,
categoriassocio,
categoria in categoriassocio,
)
if categoria != socioactivo:
response = common.addcategoria(token, socioid, categoria)
else:
response = common.addcategoria(
token,
socioid,
categoria,
extra={
"tipusperiodicitat": extras[categoria],
"dataProperaGeneracio": fechacambiosocio,
},
)