Formatting.
This commit is contained in:
parent
cd9c3b6e39
commit
a79fc533ee
11 changed files with 231 additions and 204 deletions
|
|
@ -2,19 +2,20 @@ from core.mysql_wrapper import get_anunciosdb
|
|||
|
||||
|
||||
class CapturasInterface:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.anunciosdb = get_anunciosdb()
|
||||
|
||||
def insert_captura(self, ad_data):
|
||||
|
||||
columns = ', '.join(ad_data.keys())
|
||||
placeholders_string = ', '.join(['%s'] * len(ad_data))
|
||||
columns = ", ".join(ad_data.keys())
|
||||
placeholders_string = ", ".join(["%s"] * len(ad_data))
|
||||
|
||||
query_statement = """ INSERT INTO capturas
|
||||
( fecha_captura, {} )
|
||||
VALUES( NOW(), {} )""".format(columns, placeholders_string)
|
||||
VALUES( NOW(), {} )""".format(
|
||||
columns, placeholders_string
|
||||
)
|
||||
|
||||
query_parameters = tuple([v for v in ad_data.values()])
|
||||
|
||||
|
|
@ -71,7 +72,6 @@ class CapturasInterface:
|
|||
|
||||
return result > 0
|
||||
|
||||
|
||||
def get_not_geocoded_captura(self):
|
||||
query_statement = """
|
||||
SELECT *
|
||||
|
|
@ -82,17 +82,21 @@ class CapturasInterface:
|
|||
cursor_result = self.anunciosdb.query(query_statement, dictionary=True)
|
||||
return cursor_result.fetchone()
|
||||
|
||||
def update_geo_data(self, referencia, fecha_captura, latitude, longitude, precision):
|
||||
def update_geo_data(
|
||||
self, referencia, fecha_captura, latitude, longitude, precision
|
||||
):
|
||||
query_statement = """
|
||||
UPDATE anuncios.capturas
|
||||
SET latitud = %(latitud)s, longitud = %(longitud)s, `precision` = %(precision)s
|
||||
WHERE referencia = %(referencia)s AND fecha_captura = %(fecha_captura)s
|
||||
"""
|
||||
query_parameters = {'referencia': referencia,
|
||||
'fecha_captura': fecha_captura,
|
||||
'latitud': latitude,
|
||||
'longitud': longitude,
|
||||
'precision': precision}
|
||||
query_parameters = {
|
||||
"referencia": referencia,
|
||||
"fecha_captura": fecha_captura,
|
||||
"latitud": latitude,
|
||||
"longitud": longitude,
|
||||
"precision": precision,
|
||||
}
|
||||
|
||||
self.anunciosdb.query(query_statement, query_parameters)
|
||||
|
||||
|
|
@ -114,13 +118,15 @@ class CapturasInterface:
|
|||
AND (`t1`.`fecha_captura` BETWEEN %(start_date)s AND %(end_date)s)
|
||||
)
|
||||
"""
|
||||
query_parameters = {'start_date': start_date.strftime('%Y-%m-%d 00:00:00'),
|
||||
'end_date': end_date.strftime('%Y-%m-%d 00:00:00')}
|
||||
query_parameters = {
|
||||
"start_date": start_date.strftime("%Y-%m-%d 00:00:00"),
|
||||
"end_date": end_date.strftime("%Y-%m-%d 00:00:00"),
|
||||
}
|
||||
|
||||
cursor_result = self.anunciosdb.query(query_statement, query_parameters, dictionary=True)
|
||||
cursor_result = self.anunciosdb.query(
|
||||
query_statement, query_parameters, dictionary=True
|
||||
)
|
||||
return cursor_result.fetchall()
|
||||
|
||||
|
||||
capturas_interface = CapturasInterface()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,27 @@
|
|||
import uuid
|
||||
from core.mysql_wrapper import get_tasksdb
|
||||
|
||||
class CapturingTasksInterface:
|
||||
|
||||
class CapturingTasksInterface:
|
||||
def __init__(self):
|
||||
|
||||
self.tasksdb = get_tasksdb()
|
||||
|
||||
def create_capturing_task(self, referencia, uuid_exploring=None):
|
||||
ads_root = 'https://www.idealista.com/inmueble/'
|
||||
ads_root = "https://www.idealista.com/inmueble/"
|
||||
|
||||
query_parameters = {'ad_url': ads_root + referencia,
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'status': 'Pending'}
|
||||
query_parameters = {
|
||||
"ad_url": ads_root + referencia,
|
||||
"uuid": str(uuid.uuid4()),
|
||||
"status": "Pending",
|
||||
}
|
||||
|
||||
if uuid_exploring is None:
|
||||
query_statement = """INSERT INTO capturing_tasks_logs
|
||||
(uuid, write_time, status, ad_url)
|
||||
VALUES (%(uuid)s, NOW(), %(status)s, %(ad_url)s)"""
|
||||
else:
|
||||
query_parameters['uuid_exploring'] = uuid_exploring
|
||||
query_parameters["uuid_exploring"] = uuid_exploring
|
||||
query_statement = """INSERT INTO capturing_tasks_logs
|
||||
(uuid, write_time, status, ad_url, fk_uuid_exploring)
|
||||
VALUES (%(uuid)s, NOW(), %(status)s, %(ad_url)s, %(uuid_exploring)s)"""
|
||||
|
|
@ -43,16 +45,14 @@ class CapturingTasksInterface:
|
|||
return None
|
||||
|
||||
def update_capturing_task(self, uuid, uuid_exploring, status, ad_url):
|
||||
query_parameters = {'ad_url': ad_url,
|
||||
'uuid': uuid,
|
||||
'status': status}
|
||||
query_parameters = {"ad_url": ad_url, "uuid": uuid, "status": status}
|
||||
|
||||
if uuid_exploring is None:
|
||||
query_statement = """INSERT INTO capturing_tasks_logs
|
||||
(uuid, write_time, status, ad_url)
|
||||
VALUES (%(uuid)s, NOW(), %(status)s, %(ad_url)s)"""
|
||||
else:
|
||||
query_parameters['uuid_exploring'] = uuid_exploring
|
||||
query_parameters["uuid_exploring"] = uuid_exploring
|
||||
query_statement = """INSERT INTO capturing_tasks_logs
|
||||
(uuid, write_time, status, ad_url, fk_uuid_exploring)
|
||||
VALUES (%(uuid)s, NOW(), %(status)s, %(ad_url)s, %(uuid_exploring)s)"""
|
||||
|
|
@ -74,4 +74,5 @@ class CapturingTasksInterface:
|
|||
except:
|
||||
return 999
|
||||
|
||||
|
||||
capturing_interface = CapturingTasksInterface()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ from core.mysql_wrapper import get_anunciosdb
|
|||
|
||||
|
||||
class IndicesInterface:
|
||||
|
||||
def __init__(self):
|
||||
self.anunciosdb = get_anunciosdb()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue