Skip to content

Commit 07ad163

Browse files
committed
Initial
1 parent 3916242 commit 07ad163

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

satdigitalinvoice/prediales.py

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,69 +21,29 @@ def request_predial(predial: str):
2121
predial = format_clavecat(predial)
2222

2323
r = requests.post(
24-
url="https://predial.torreon.gob.mx/app/php/get_datos_predio.php",
24+
url="https://pagoenlinea-api.torreon.gob.mx/api/predial/consultar",
2525
data={
26-
"txt_clavecat": predial
26+
"cveCatastral": predial
2727
}
2828
)
2929
if r.status_code == 200:
30-
return _parse_response(r.content)
30+
return r.json()
3131

3232
raise ResponseError(r)
3333

3434

3535
def process_predial(folder, predial: str):
3636
res = request_predial(predial)
3737

38-
if pr := res['predial_recibo']:
39-
r = requests.get(
40-
url=pr
41-
)
42-
pdf_file = os.path.join(folder, f"{predial}.pdf")
43-
with open(pdf_file, "wb") as f:
44-
f.write(r.content)
45-
46-
if pec := res['predial_estado_cuenta']:
47-
r = requests.get(
48-
url=pec
49-
)
50-
pdf_file = os.path.join(folder, f"{predial}_adeudo.pdf")
51-
with open(pdf_file, "wb") as f:
52-
f.write(r.content)
53-
5438
yaml_file = os.path.join(folder, f"{predial}.yaml")
5539
with open(yaml_file, "w", encoding="utf-8") as fs:
5640
yaml.dump(res, fs, Dumper=NoAliasDumper, allow_unicode=True, width=1280, sort_keys=False)
5741

58-
59-
def _parse_response(data):
60-
if b'No se ha encontrado coincidencia con su clave catastral' in data:
61-
return None
62-
if b'La cuenta se encuentra excenta de pago' in data:
63-
return None
64-
65-
res = {}
66-
html = BeautifulSoup(data, 'html.parser')
67-
i = html.find_all(name="td")
68-
for k, v in batched(i, 2): # iterate in pairs
69-
res[k.text.strip().rstrip(":")] = v.text.strip()
70-
71-
i = html.find_all(name="div", attrs={"class": "text-xs font-weight-bold text-primary text-uppercase mb-1"})
72-
j = html.find_all(name="div", attrs={"class": "encabezado-principal mb-0 font-weight-bold text-gray-800"})
73-
74-
for k, v in zip(i, j):
75-
res[k.text.strip()] = v.text.split("$", maxsplit=1)[1]
76-
77-
i = html.find_all(name="div", attrs={"class": "text-xs font-weight-bold text-primary text-uppercase mb-1 text-center"})
78-
res['TOTAL'] = i[0].text.split("$", maxsplit=1)[1]
79-
80-
i = html.find_all(name="a")
81-
for k in i:
82-
href = k['href']
83-
for v in ["predial_estado_cuenta", "predial_recibo"]:
84-
if v in href:
85-
res[v] = href
86-
else:
87-
res[v] = None
88-
89-
return res
42+
edo_cta = res['datosEdoCta']
43+
url_adeudo = f"https://app.torreon.gob.mx/httpmethods/predial_estado_cuenta?adeudo_id={edo_cta['K_ADEUDO']}"
44+
r = requests.get(
45+
url=url_adeudo
46+
)
47+
pdf_file = os.path.join(folder, f"{predial}.pdf")
48+
with open(pdf_file, "wb") as f:
49+
f.write(r.content)

0 commit comments

Comments
 (0)