Skip to content

Commit

Permalink
Merge branch 'atribs_liquidacion_sucursal'
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloCastellano authored and Pablo Castellano committed Mar 12, 2017
2 parents 1066fb8 + 05e0097 commit 183c808
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bormeparser/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def parse(self):
if not isinstance(id_anuncio, int):
continue
data = anuncios[id_anuncio]
a = BormeAnuncio(id_anuncio, data['Empresa'], data['Actos'], data['Registro'])
a = BormeAnuncio(id_anuncio, data['Empresa'], data['Actos'], data['Extra'])
bormeanuncios.append(a)

fecha = regex_fecha(anuncios['borme_fecha'])
Expand Down
10 changes: 4 additions & 6 deletions bormeparser/backends/pypdf2/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _parse(self):
nombreacto = None
DATA[anuncio_id] = {
'Empresa': empresa,
'Registro': registro,
'Extra': extra,
'Actos': self.actos
}

Expand Down Expand Up @@ -157,12 +157,10 @@ def _parse(self):
logger.debug('END: cabecera')
cabecera = False
data = self._clean_data(data)
anuncio_id, empresa, registro = regex_empresa(data, sanitize=self.sanitize)
if registro is None:
registro = ""
anuncio_id, empresa, extra = regex_empresa(data, sanitize=self.sanitize)
logger.debug(' anuncio_id: %s' % anuncio_id)
logger.debug(' empresa: %s' % empresa)
logger.debug(' registro: %s' % registro)
logger.debug(' extra: {}'.format(extra))
data = ""
if texto:
logger.debug('END: texto')
Expand Down Expand Up @@ -262,7 +260,7 @@ def _parse(self):
self._parse_acto(nombreacto, data, prefix='END')
DATA[anuncio_id] = {
'Empresa': empresa,
'Registro': registro,
'Extra': extra,
'Actos': self.actos
}

Expand Down
15 changes: 10 additions & 5 deletions bormeparser/borme.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ class BormeAnuncio(object):
Representa un anuncio con un conjunto de actos mercantiles (Constitucion, Nombramientos, ...)
"""

def __init__(self, id, empresa, actos, registro=None, datos_registrales=None):
logger.debug(u"new BormeAnuncio({}) {} ({})".format(id, empresa, registro))
def __init__(self, id, empresa, actos, extra, datos_registrales=None):
logger.debug(u"new BormeAnuncio({}) {} ({})".format(id, empresa, extra))
self.id = id
self.empresa = empresa
self.registro = registro
self.registro = extra["registro"]
self.sucursal = extra["sucursal"]
self.liquidacion = extra["liquidacion"]
self.datos_registrales = datos_registrales or ""
self._set_actos(actos)

Expand All @@ -164,7 +166,7 @@ def get_actos(self):
yield acto.name, acto.value

def __repr__(self):
return "<BormeAnuncio({}) {} ({}) ({})>".format(self.id, self.empresa, self.registro, len(self.actos))
return "<BormeAnuncio({}) {} (r:{}, s:{}, l:{}) ({})>".format(self.id, self.empresa, self.registro, self.sucursal, self.liquidacion, len(self.actos))


# TODO: guardar self.filepath si from_file, y si from_date y luego save_to_file tb
Expand Down Expand Up @@ -482,6 +484,8 @@ def _to_dict(self, set_url=True):
doc['anuncios'][anuncio.id] = {
'empresa': anuncio.empresa,
'registro': anuncio.registro,
'sucursal': anuncio.sucursal,
'liquidacion': anuncio.liquidacion,
'datos registrales': anuncio.datos_registrales,
'actos': [],
'num_actos': 0
Expand Down Expand Up @@ -549,7 +553,8 @@ def from_json(self, filename):
bormeanuncios = []
anuncios = sorted(d['anuncios'].items(), key=lambda t: t[0])
for id_anuncio, data in anuncios:
a = BormeAnuncio(int(id_anuncio), data['empresa'], data['actos'], data['registro'], data['datos registrales'])
extra = {"liquidacion": data["liquidacion"], "sucursal": data["sucursal"], "registro": data["registro"]}
a = BormeAnuncio(int(id_anuncio), data['empresa'], data['actos'], extra, data['datos registrales'])
bormeanuncios.append(a)
borme = Borme(date, seccion, provincia, num, cve, bormeanuncios, filename)
borme._url = url
Expand Down
3 changes: 1 addition & 2 deletions bormeparser/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
}


# TODO: Devolver palabras clave como SICAV, SUCURSAL EN ESPAÑA, EN LIQUIDACION
# UNION TEMPORAL DE EMPRESAS LEY 18 1982 DE 26 DE MAYO
# TODO: UNION TEMPORAL DE EMPRESAS LEY 18 1982 DE 26 DE MAYO
def clean_empresa(nombre):
nombre = nombre.rstrip(".")
sucursal_spain = False
Expand Down
17 changes: 12 additions & 5 deletions bormeparser/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,36 @@ def regex_empresa_tipo(data):

def regex_empresa(data, sanitize=True):
""" Captura el número de acto y el nombre de la empresa
Si el nombre incluye el nombre de un registro mercantil, lo devuelve como tercer parámetro (sino None)
Si el nombre incluye el nombre de un registro mercantil, lo devuelve en el tercer parámetro
El tercer parámetro contiene información extra de la empresa
data: "57344 - ALDARA CATERING SL"
data: "473700 - SA COVA PLAÇA MAJOR SL(R.M. PALMA DE MALLORCA)"
"""

extra = {"liquidacion": False, "sucursal": False, "registro": ""}
res = REGEX_EMPRESA_REGISTRO.match(data)
if res:
acto_id, empresa, registro = res.groups()
if registro not in ALL_REGISTROS:
logger.warning("Registro desconocido: " + registro)
else:
registro = REGISTROS[registro]
extra["registro"] = REGISTROS[registro]
else:
acto_id, empresa = REGEX_EMPRESA.match(data).groups()
registro = None

empresa = re.sub(" EN LIQUIDACION$", "", empresa)
empresa = re.sub(u" SUCURSAL EN ESPAÑA$", "", empresa)
if empresa.endswith(" EN LIQUIDACION"):
extra["liquidacion"] = True
empresa = re.sub(" EN LIQUIDACION$", "", empresa)

if empresa.endswith(u" SUCURSAL EN ESPAÑA"):
extra["sucursal"] = True
empresa = re.sub(u" SUCURSAL EN ESPAÑA$", "", empresa)

if sanitize:
empresa = clean_empresa(empresa)
return int(acto_id), empresa, registro
return int(acto_id), empresa, extra


def regex_cargos(data, sanitize=True):
Expand Down
10 changes: 6 additions & 4 deletions bormeparser/tests/test_borme.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{'Datos registrales': 'T 5188, L 4095, F 146, S 8, H MA120039, I/A 4 (25.05.15).'},
{'Constitución': 'Comienzo de operaciones: 1.04.15. Objeto social: blabla. Domicilio: C/ RANDOM 1 2 (MALAGA). Capital: 3.000,00 Euros.'},
{'Nombramientos': {'Adm. Unico': {'PEDRO GOMEZ GOMEZ'}}}],
'Registro': 'R.M. MAHON',
'Extra': {"liquidacion": False, "sucursal": False, "registro": "R.M. MAHON"},
'Empresa': 'EMPRESA RANDOM SL.'},
'borme_cve': 'BORME-A-2015-102-29',
'borme_fecha': 'Martes 2 de junio de 2015',
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_json(self):
class FakeBormeTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
bormeanuncios = [BormeAnuncio(1, DATA1[214]['Empresa'], DATA1[214]['Actos'], DATA1[214]['Registro'])]
bormeanuncios = [BormeAnuncio(1, DATA1[214]['Empresa'], DATA1[214]['Actos'], DATA1[214]['Extra'])]
cls.borme = Borme((2015, 2, 10), 'A', PROVINCIA.CACERES, 27, 'BORME-A-2015-27-10', bormeanuncios)

def test_instance(self):
Expand Down Expand Up @@ -137,12 +137,14 @@ def test_to_json(self):

class BormeAnuncioTestCase(unittest.TestCase):
def setUp(self):
self.anuncio = BormeAnuncio(1, DATA1[214]['Empresa'], DATA1[214]['Actos'], DATA1[214]['Registro'])
self.anuncio = BormeAnuncio(1, DATA1[214]['Empresa'], DATA1[214]['Actos'], DATA1[214]['Extra'])

def test_instance(self):
self.assertEqual(self.anuncio.id, 1)
self.assertEqual(self.anuncio.empresa, DATA1[214]['Empresa'])
self.assertEqual(self.anuncio.registro, DATA1[214]['Registro'])
self.assertEqual(self.anuncio.registro, DATA1[214]['Extra']["registro"])
self.assertEqual(self.anuncio.sucursal, DATA1[214]['Extra']["sucursal"])
self.assertEqual(self.anuncio.liquidacion, DATA1[214]['Extra']["liquidacion"])
self.assertEqual(self.anuncio.datos_registrales, DATA1[214]['Actos'][1]['Datos registrales'])

def test_get_actos(self):
Expand Down
40 changes: 32 additions & 8 deletions bormeparser/tests/test_bormeregex.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,53 @@ class BormeparserRegexEmpresaTestCase(unittest.TestCase):
acto2 = '57344 - ALDARA CATERING SL'
acto3 = u'473700 - SA COVA PLAÇA MAJOR SL(R.M. PALMA DE MALLORCA)'
acto4 = u'111141 - CAMAPLAS, S.L.(R.M. LAS PALMAS).'
acto5 = "114033 - PARTEI VALENCIA SOCIEDAD LIMITADA EN LIQUIDACION"
acto6 = "106606 - PLANTRONICS BV SUCURSAL EN ESPAÑA."
empresa1 = 'ALDARA CATERING SL'
empresa2 = 'ALDARA CATERING'

def test_regex_empresa(self):
acto_id, empresa, registro = regex_empresa(self.acto1)
acto_id, empresa, extra = regex_empresa(self.acto1)
self.assertEqual(acto_id, 57344)
self.assertEqual(empresa, 'ALDARA CATERING SL')
self.assertEqual(registro, None)
self.assertEqual(extra["registro"], "")
self.assertEqual(extra["liquidacion"], False)
self.assertEqual(extra["sucursal"], False)

acto_id, empresa, registro = regex_empresa(self.acto2)
acto_id, empresa, extra = regex_empresa(self.acto2)
self.assertEqual(acto_id, 57344)
self.assertEqual(empresa, 'ALDARA CATERING SL')
self.assertEqual(registro, None)
self.assertEqual(extra["registro"], "")
self.assertEqual(extra["liquidacion"], False)
self.assertEqual(extra["sucursal"], False)

acto_id, empresa, registro = regex_empresa(self.acto3)
acto_id, empresa, extra = regex_empresa(self.acto3)
self.assertEqual(acto_id, 473700)
self.assertEqual(empresa, u'SA COVA PLAÇA MAJOR SL')
self.assertEqual(registro, 'Palma de Mallorca')
self.assertEqual(extra["registro"], 'Palma de Mallorca')
self.assertEqual(extra["liquidacion"], False)
self.assertEqual(extra["sucursal"], False)

acto_id, empresa, registro = regex_empresa(self.acto4)
acto_id, empresa, extra = regex_empresa(self.acto4)
self.assertEqual(acto_id, 111141)
self.assertEqual(empresa, 'CAMAPLAS, SL')
self.assertEqual(registro, 'Las Palmas (Canarias)')
self.assertEqual(extra["registro"], 'Las Palmas (Canarias)')
self.assertEqual(extra["liquidacion"], False)
self.assertEqual(extra["sucursal"], False)

acto_id, empresa, extra = regex_empresa(self.acto5)
self.assertEqual(acto_id, 114033)
self.assertEqual(empresa, 'PARTEI VALENCIA SL')
self.assertEqual(extra["registro"], "")
self.assertEqual(extra["liquidacion"], True)
self.assertEqual(extra["sucursal"], False)

acto_id, empresa, extra = regex_empresa(self.acto6)
self.assertEqual(acto_id, 106606)
self.assertEqual(empresa, "PLANTRONICS BV")
self.assertEqual(extra["registro"], "")
self.assertEqual(extra["liquidacion"], False)
self.assertEqual(extra["sucursal"], True)

def test_regex_empresa_tipo(self):
empresa, tipo = regex_empresa_tipo(self.empresa1)
Expand Down

0 comments on commit 183c808

Please sign in to comment.