Skip to content

Commit

Permalink
BormeXML.get_provincias()
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloCastellano committed Apr 16, 2017
1 parent 020a696 commit 1f9e486
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Version 0.3.0 [unreleased]
- Incluye nombre del R.M. en BORME-JSON
- Cambios menores en los scripts
- Borme.XML devuelve str en lugar de list si solo hay un elemento
- BormeXML.get_provincias

Version 0.2.4 [2016-09-21]
--------------------------
Expand Down
11 changes: 11 additions & 0 deletions bormeparser/borme.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ def get_sizes(self, seccion=None, provincia=None):
sizes[cve] = int(size)
return sizes

def get_provincias(self, seccion):
protocol = 'https' if self.use_https else 'http'
url_base = URL_BASE % protocol

xpath = '//sumario/diario/seccion[@num="{}"]/emisor/item/titulo/text()'.format(seccion)
provincias = self.xml.xpath(xpath)
provincias.remove(u"ÍNDICE ALFABÉTICO DE SOCIEDADES")
return provincias

# TODO: Los nombres en el XML vienen en sus respectivos idiomas
# Mientras que PROVINCIA.provincia.GERONA no retornaría nada
def _build_xpath(self, seccion=None, provincia=None):
"""
Devuelve una lista con los elementos item
Expand Down
2 changes: 1 addition & 1 deletion bormeparser/provincia.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ def from_title(title):
except AttributeError:
raise ValueError('InvalidProvince: %s' % title)

ALL_PROVINCIAS = list(filter(lambda x: not x.startswith('__') and x != 'from_title', vars(PROVINCIA)))
ALL_PROVINCIAS = list(filter(lambda x: not x.startswith('__') and x != 'from_title', vars(PROVINCIA)))
12 changes: 10 additions & 2 deletions bormeparser/tests/test_borme.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,20 @@ def test_get_cves(self):
]

self.assertEqual(self.bxml.get_cves(SECCION.A), seccion_a_bormes)
self.assertEqual(self.bxml.get_cves(SECCION.A, 'MADRID'), ['BORME-A-2015-183-28'])
self.assertEqual(self.bxml.get_cves(SECCION.A, 'MADRID'), 'BORME-A-2015-183-28')
self.assertEqual(self.bxml.get_cves(SECCION.B), seccion_b_bormes)
self.assertEqual(self.bxml.get_cves(SECCION.B, 'MADRID'), ['BORME-B-2015-183-28'])
self.assertEqual(self.bxml.get_cves(SECCION.B, 'MADRID'), 'BORME-B-2015-183-28')
self.assertEqual(self.bxml.get_cves(SECCION.C), seccion_c_bormes)
self.assertEqual(self.bxml.get_cves(), seccion_a_bormes + seccion_b_bormes + seccion_c_bormes)

def test_get_provincias(self):
provincias = ['ARABA/ÁLAVA', 'ALICANTE', 'ALMERÍA', 'BADAJOZ', 'ILLES BALEARS', 'BARCELONA', 'BURGOS', 'CÁCERES', 'CÁDIZ', 'CASTELLÓN', 'CÓRDOBA',
'A CORUÑA', 'CUENCA', 'HUESCA', 'LLEIDA', 'LA RIOJA', 'MADRID', 'MÁLAGA', 'MURCIA', 'NAVARRA', 'OURENSE', 'ASTURIAS', 'PALENCIA',
'LAS PALMAS', 'PONTEVEDRA', 'SANTA CRUZ DE TENERIFE', 'CANTABRIA', 'SEGOVIA', 'SEVILLA', 'TARRAGONA', 'VALENCIA', 'VALLADOLID',
'ZAMORA', 'ZARAGOZA', 'CEUTA']

self.assertEqual(self.bxml.get_provincias(SECCION.A), provincias)

def test_get_sizes(self):
seccion_a_sizes = {'BORME-A-2015-183-01': 264270,
'BORME-A-2015-183-03': 245244,
Expand Down

0 comments on commit 1f9e486

Please sign in to comment.