Added option to execute the script with a specific json coordinate file.

This commit is contained in:
J 2019-09-17 10:48:16 +02:00
parent 89b3cb5994
commit 832f0e6239
2 changed files with 18 additions and 11 deletions

View File

@ -1,4 +1,9 @@
import sys
from src.librecatastro.catastro_scrapper import CadastroScrapper
if __name__ == "__main__":
CadastroScrapper.scrap_all()
filename = ''
if len(sys.argv) > 1:
filename = sys.argv[1]
CadastroScrapper.scrap_all(filename)

View File

@ -37,18 +37,20 @@ class CadastroScrapper:
""" Scrapping main calls """
@staticmethod
def scrap_all():
def scrap_all(filename=''):
for r, d, files in os.walk(config['coordinates_path']):
for file in files:
if '.json' in file:
f = open(os.path.join(config['coordinates_path'], file), "r")
content = f.read()
try:
bb = KibanaGeoBoundingBox(content)
coordinates_tuple = bb.get_coordinates_tuple()
CadastroScrapper.scrap_range_of_coordinates(coordinates_tuple[0], coordinates_tuple[1], coordinates_tuple[2], coordinates_tuple[3])
except:
logger.error("{} is not formatted properly. Please take a look at the examples.".format(file))
print(file, filename)
if '.json' in file and ((filename != '' and file == filename) or filename == ''):
print(file)
f = open(os.path.join(config['coordinates_path'], file), "r")
content = f.read()
try:
bb = KibanaGeoBoundingBox(content)
coordinates_tuple = bb.get_coordinates_tuple()
CadastroScrapper.scrap_range_of_coordinates(coordinates_tuple[0], coordinates_tuple[1], coordinates_tuple[2], coordinates_tuple[3])
except:
logger.error("{} is not formatted properly. Please take a look at the examples.".format(file))
@staticmethod
def scrap_range_of_coordinates(long_min, long_max, lat_min, lat_max):