mirror of
https://github.com/josejuanmartinez/libreCatastro.git
synced 2024-07-06 15:22:28 +02:00
Fixes problem that was sending prov_num and city_num instead of prov_name and city_name
This commit is contained in:
parent
af53ec5b4e
commit
062cce6e03
@ -58,6 +58,7 @@ class CadasterEntry:
|
||||
es = Elasticsearch()
|
||||
try:
|
||||
query = '{"query":{"bool":{"must":[{"match":{"cadaster":"' + self.cadaster + '"}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}'
|
||||
print(query)
|
||||
res = es.search(index=config['elasticsearch-index'], body=query)
|
||||
hits = DotMap(res).hits.total
|
||||
if hits == DotMap():
|
||||
|
@ -52,11 +52,11 @@ class ParserXML(Parser):
|
||||
entry = ScrapperXML.get_cadaster_entries_by_cadaster('', '', ''.join([pc1, pc2]))
|
||||
picture = None
|
||||
if entry.consulta_dnp.bico.bi.dt.loine != DotMap():
|
||||
prov_num = entry.consulta_dnp.bico.bi.dt.loine.cp
|
||||
city_num = entry.consulta_dnp.bico.bi.dt.cmc
|
||||
|
||||
# Parcela
|
||||
if pictures:
|
||||
prov_num = entry.consulta_dnp.bico.bi.dt.loine.cp
|
||||
city_num = entry.consulta_dnp.bico.bi.dt.cmc
|
||||
if prov_num != DotMap() and city_num != DotMap():
|
||||
if pictures and prov_num != DotMap() and city_num != DotMap():
|
||||
picture = Scrapper.scrap_site_picture(prov_num, city_num, ''.join([pc1, pc2]))
|
||||
cadaster_entry = CadasterEntryXML(entry, x, y, picture)
|
||||
cadaster_entry.to_elasticsearch()
|
||||
@ -83,7 +83,7 @@ class ParserXML(Parser):
|
||||
|
||||
try:
|
||||
# Try to get info by complete cadaster num
|
||||
sub_entry = ScrapperXML.get_cadaster_entries_by_cadaster(prov_num, city_num, cadaster)
|
||||
sub_entry = ScrapperXML.get_cadaster_entries_by_cadaster('', '', cadaster)
|
||||
except:
|
||||
# Cadastro did not return anything by cadaster entry (error? bug?)
|
||||
# Try to get it by complete address
|
||||
@ -260,7 +260,7 @@ class ParserXML(Parser):
|
||||
|
||||
try:
|
||||
# Try to get info by complete cadaster num
|
||||
sub_entry = ScrapperXML.get_cadaster_entries_by_cadaster(prov_num, city_num, cadaster)
|
||||
sub_entry = ScrapperXML.get_cadaster_entries_by_cadaster(prov_name, city_name, cadaster)
|
||||
except:
|
||||
# Cadastro did not return anything by cadaster entry (error? bug?)
|
||||
# Try to get it by complete address
|
||||
|
@ -33,11 +33,11 @@ class ScrapperXML(Scrapper):
|
||||
return xml_dict_map
|
||||
|
||||
@classmethod
|
||||
def get_cadaster_entries_by_cadaster(cls, provincia, municipio, rc):
|
||||
def get_cadaster_entries_by_cadaster(cls, prov_name, city_name, rc):
|
||||
""" provincia and municipio are optional and can be set to '' """
|
||||
|
||||
params = {"Provincia": provincia,
|
||||
"Municipio": municipio,
|
||||
params = {"Provincia": prov_name,
|
||||
"Municipio": city_name,
|
||||
"RC": rc}
|
||||
|
||||
url = cls.URL_LOCATIONS_BASE.format("/OVCCallejero.asmx/Consulta_DNPRC")
|
||||
|
@ -1,4 +1,5 @@
|
||||
import unittest
|
||||
from time import sleep
|
||||
|
||||
from src.librecatastro.scrapping.parsers.parser_xml import ParserXML
|
||||
|
||||
@ -8,12 +9,21 @@ class ParserXMLTests(unittest.TestCase):
|
||||
def test_search_by_coordinates_creates_and_stores_in_elasticsearch(self):
|
||||
cadaster_list = ParserXML.process_search_by_coordinates(-3.47600944027389, 40.5370635727521)
|
||||
self.assertEqual(len(cadaster_list), 14)
|
||||
sleep(5)
|
||||
for cadaster in cadaster_list:
|
||||
self.assertTrue(cadaster.from_elasticsearch())
|
||||
|
||||
def test_search_by_coordinates_creates_and_stores_in_elasticsearch_2(self):
|
||||
cadaster_list = ParserXML.process_search_by_coordinates(-3.4824836111042, 40.5365759179981)
|
||||
self.assertEqual(len(cadaster_list), 61)
|
||||
sleep(5)
|
||||
for cadaster in cadaster_list:
|
||||
self.assertTrue(cadaster.from_elasticsearch())
|
||||
|
||||
def test_search_by_provinces_creates_and_stores_in_elasticsearch(self):
|
||||
cadaster_list = ParserXML.process_search_by_provinces(['MADRID'], max_times=1)
|
||||
self.assertEqual(len(cadaster_list), 1)
|
||||
sleep(5)
|
||||
for cadaster in cadaster_list:
|
||||
self.assertTrue(cadaster.from_elasticsearch())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user