2018-10-18 22:48:09 +02:00
|
|
|
import sys
|
2020-11-03 07:29:17 +01:00
|
|
|
|
|
|
|
|
sys.path.append("..")
|
2018-10-14 19:24:17 +02:00
|
|
|
from time import sleep
|
|
|
|
|
from db_layer.capturas_interface import capturas_interface
|
|
|
|
|
from db_layer.capturing_tasks_interface import capturing_interface
|
2018-12-01 16:26:25 +01:00
|
|
|
from core.config import refresher_delay
|
2020-11-15 13:21:08 +01:00
|
|
|
from core import my_logger
|
|
|
|
|
import logging
|
2018-10-18 22:36:10 +02:00
|
|
|
|
2018-12-18 20:05:08 +01:00
|
|
|
|
2018-10-14 19:24:17 +02:00
|
|
|
class Refresher:
|
|
|
|
|
def start(self):
|
|
|
|
|
|
|
|
|
|
while True:
|
2018-12-01 16:26:25 +01:00
|
|
|
sleep(refresher_delay)
|
2018-10-14 19:24:17 +02:00
|
|
|
|
2020-11-15 13:21:08 +01:00
|
|
|
logging.info("Checking for ads that need to be refreshed...")
|
2018-12-18 20:05:08 +01:00
|
|
|
old_ad = capturas_interface.get_old_ad()
|
|
|
|
|
if old_ad:
|
2020-11-15 13:21:08 +01:00
|
|
|
logging.info("Found an old ad.")
|
2020-11-03 07:29:17 +01:00
|
|
|
capturing_interface.create_capturing_task(str(old_ad["referencia"]))
|
2018-10-14 19:24:17 +02:00
|
|
|
|
2018-10-16 21:19:35 +02:00
|
|
|
@staticmethod
|
|
|
|
|
def dead_ad_checker(html):
|
|
|
|
|
"""
|
|
|
|
|
Comprueba si el html es de un anuncio dado de baja.
|
|
|
|
|
:param html: HTML del anuncio en string.
|
2018-10-19 17:22:09 +02:00
|
|
|
:return: True si esta dado de baja, False si no.
|
2018-10-16 21:19:35 +02:00
|
|
|
"""
|
2018-10-19 18:05:35 +02:00
|
|
|
try:
|
2020-11-03 07:29:17 +01:00
|
|
|
if ":-|" in html or "El anunciante lo dio de baja" in html:
|
2018-10-19 18:05:35 +02:00
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
except TypeError:
|
2018-10-16 21:19:35 +02:00
|
|
|
return False
|
2018-10-14 19:24:17 +02:00
|
|
|
|
|
|
|
|
|
2020-11-03 07:29:17 +01:00
|
|
|
if __name__ == "__main__":
|
2018-10-18 22:36:10 +02:00
|
|
|
refresher = Refresher()
|
|
|
|
|
refresher.start()
|