Skip to content

Commit

Permalink
doc: tutorial parsing example
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloCastellano committed Jun 28, 2015
1 parent e7d5cbc commit 7ae0e83
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bormeparser/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def download_pdf(date, filename, seccion, provincia, parse=False):
return False
if parse:
return parse_borme(filename)

return True


Expand Down
82 changes: 75 additions & 7 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ Pero podemos usar otras funciones para descargar el BORME directamente de ese d
date = (2015, 6, 2)
path = '/tmp/BORME-A-2015-102-29.pdf'
borme = bormeparser.download_pdf(date, path, bormeparser.SECCION.A, bormeparser.PROVINCIA.MALAGA)
Si no ha habido ningún error (problema de conexión, el BORME de esa fecha no existe, ...) la variable borme
es una instancia de Borme:
downloaded = bormeparser.download_pdf(date, path, bormeparser.SECCION.A, bormeparser.PROVINCIA.MALAGA)
.. code-block:: python
>>> print(borme)
<Borme(2015-06-02) seccion:A provincia:29>
>>> print(donloaded)
True
Para conocer la url de un PDF, bormeparser internamente descarga el archivo XML del día y ahí encuentra la ruta.
Podemos obtener dicho archivo XML así:
Expand All @@ -48,6 +45,77 @@ Podemos obtener dicho archivo XML así:
>>> bormeparser.download_xml(date, '/tmp/20150602.xml')
True
Parsear un archivo PDF de BORME:

.. code-block:: python
borme = bormeparser.parse('/tmp/BORME-A-2015-102-29.pdf')
.. code-block:: python
>>> print(borme)
<Borme(2015-06-02) seccion:SECCIÓN PRIMERA provincia:MÁLAGA>
Uso avanzado
------------
------------

Descargar y parsear un PDF de BORME:

.. code-block:: python
borme = bormeparser.download_pdf(date, path, bormeparser.SECCION.A, bormeparser.PROVINCIA.MALAGA, parse=True)
Si no ha habido ningún error (problema de conexión, el BORME de esa fecha no existe, ...) la variable borme
es una instancia de Borme:

.. code-block:: python
>>> print(borme)
<Borme(2015-06-02) seccion:SECCIÓN PRIMERA provincia:MÁLAGA>
Borme y BormeActo
-----------------

.. code-block:: python
>>> borme.num
102
>>> borme.info
{}
>>> borme.date
datetime.date(2015, 6, 2)
>>> borme.provincia
'MÁLAGA'
>>> borme.seccion
'SECCIÓN PRIMERA'
>>> for acto in borme.get_actos():
... print(acto)
...
[...]
<BormeActo(223969) RUILERENA SL. (4)>
<BormeActo(223970) REMOTONIO SL. (3)>
<BormeActo(223971) GARPAPACIA SL. (3)>
<BormeActo(223972) GARIETOCIA SL. (3)>
<BormeActo(223973) PROAS INGENIERIA SL. (3)>
<BormeActo(223974) LORECUALAR SL. (4)>
<BormeActo(223976) DELCAVO SL. (4)>
<BormeActo(223977) A. RANDO 2004 SL. (1)>
<BormeActo(223978) DISTRIBUIDORA MALAGUEÑA DE EXPLOSIVOS SL. (1)>
<BormeActo(223979) HMFALGARROBO SL. (2)>
<BormeActo(223980) SERVICIOS BASICOS MALAGA SL. (2)>
<BormeActo(223981) PALUSTRIS INVERSIONES SL. (1)>
<BormeActo(223982) LANDEVANT SL. (1)>
<BormeActo(223983) RESTAURACIONES FERROVIARIAS SL. (1)>
<BormeActo(223984) BCM GESTION DE SERVICIOS SL. (1)>
<BormeActo(223986) VIAJES EUROPA TOURS SA. (2)>
<BormeActo(223987) FUERTE EL ROMPIDO SL. (1)>
<BormeActo(223988) JEWELLERY THEATRE IBERIA SL. (3)>
<BormeActo(223989) AF ASESORIA DE EMPRESAS SL. (1)>
[...]
>>> acto = borme.get_acto(223978)
>>> acto
<BormeActo(223978) DISTRIBUIDORA MALAGUEÑA DE EXPLOSIVOS SL. (1)>
>>> acto.get_actos()
{'Datos registrales': 'T 1728, L 641, F 141, S 8, H MA 22254, I/A 10 (21.05.15).', 'Nombramientos': [('Apoderado', {'GRACIAN ALCAIDE ALBERTO JAVIER'})]}

0 comments on commit 7ae0e83

Please sign in to comment.