2018-10-18 22:48:09 +02:00
|
|
|
import sys
|
2018-10-18 22:47:13 +02: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
|
2018-10-18 22:36:10 +02: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
|
|
|
|
|
|
|
|
if capturas_interface.old_ads_exist():
|
|
|
|
|
old_ad = capturas_interface.get_old_ad()
|
2018-10-18 22:36:10 +02: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:
|
|
|
|
|
if ':-|' in html or 'El anunciante lo dio de baja' in html:
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2018-10-18 22:36:10 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
refresher = Refresher()
|
|
|
|
|
refresher.start()
|
|
|
|
|
|
|
|
|
|
|
2018-10-14 19:24:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|