Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

descargar listado de organos por CCAA usando la API de infosubvenciones #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions scripts/organos-por-ccaa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import requests
import warnings
from pathlib import Path
import json

url_base = "https://www.infosubvenciones.es/bdnstrans/organos?code=A&value={:02d}"
n_ccaa = 19

def main():
organos_por_ccaa = {}
for i in range(1, n_ccaa+1):
print(f"\r[{i:2d}/{n_ccaa:2d}]")
request_listado = requests.get(url_base.format(i), verify=False)
assert request_listado.status_code == 200
listado_organos = request_listado.json()
ccaa = { item['nivel1'] for item in listado_organos }
organos = [ item["strdescripcion"] for item in listado_organos ]
organos_por_ccaa[ccaa.pop()] = organos
exportar_json(organos_por_ccaa, json_indent = 2)

def exportar_json(organos_por_ccaa, json_indent):
out_path = Path(__file__).parents[1] / "files" / "organos_por_ccaa.json"
organos_jsonified = json.dumps(
organos_por_ccaa,
indent = json_indent,
ensure_ascii = False
)
out_path.write_text(organos_jsonified)

if __name__ == "__main__":
main()