Compare commits
10 commits
6122f74e99
...
d6f4de006e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6f4de006e | ||
|
|
a0d11dcdd6 | ||
|
|
c7ddbb035f | ||
|
|
744a0a38d4 | ||
|
|
575dadaaff | ||
|
|
5e023edb00 | ||
|
|
f10b62bfd2 | ||
|
|
50a56091b9 | ||
|
|
3740ab2ada | ||
|
|
639de7c602 |
2 changed files with 22 additions and 16 deletions
|
|
@ -1,3 +1,6 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append("..")
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
@ -13,6 +16,7 @@ from core.throttling_utils import (
|
||||||
)
|
)
|
||||||
from refresher.refresher import Refresher
|
from refresher.refresher import Refresher
|
||||||
from core.parsing_utils import *
|
from core.parsing_utils import *
|
||||||
|
from core import my_logger
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,12 +87,11 @@ class Capturer:
|
||||||
self.last_try_datetime = datetime.datetime.now()
|
self.last_try_datetime = datetime.datetime.now()
|
||||||
task.capture()
|
task.capture()
|
||||||
|
|
||||||
if task.status == "Data ready":
|
if not task.status == "Data ready":
|
||||||
ad_data = task.get_ad_data()
|
|
||||||
else:
|
|
||||||
logging.warning("Something went wrong, not adding data.")
|
logging.warning("Something went wrong, not adding data.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
ad_data = task.get_ad_data()
|
||||||
self._capturas_interface.insert_captura(ad_data)
|
self._capturas_interface.insert_captura(ad_data)
|
||||||
task.update_status("Captura inserted")
|
task.update_status("Captura inserted")
|
||||||
logging.info("New ad inserted.")
|
logging.info("New ad inserted.")
|
||||||
|
|
@ -154,18 +157,22 @@ class CapturingTask:
|
||||||
attack.attack()
|
attack.attack()
|
||||||
|
|
||||||
if attack.success:
|
if attack.success:
|
||||||
|
logging.info("URL attack successful.")
|
||||||
self._parse_html(html=attack.get_text())
|
self._parse_html(html=attack.get_text())
|
||||||
return
|
return
|
||||||
|
|
||||||
if not attack.success:
|
if not attack.success:
|
||||||
|
logging.info("URL attack failed.")
|
||||||
try:
|
try:
|
||||||
if self._is_dead_ad(attack.get_text()):
|
if self._is_dead_ad(attack.get_text()):
|
||||||
self.update_status("Dead ad")
|
self.update_status("Dead ad")
|
||||||
|
logging.info("Ad was tagged as dead.")
|
||||||
return
|
return
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logging.error(
|
logging.error(
|
||||||
"Something went wrong when checking if the ad is gone"
|
"Something went wrong when checking if the ad is gone"
|
||||||
)
|
)
|
||||||
|
logging.error(AttributeError)
|
||||||
|
|
||||||
self.update_status("Fail {}".format(self.request_failures))
|
self.update_status("Fail {}".format(self.request_failures))
|
||||||
self.request_failures += 1
|
self.request_failures += 1
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
import sys
|
import logging
|
||||||
|
|
||||||
sys.path.append("..")
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
from core.config import refresher_delay
|
||||||
from db_layer.capturas_interface import capturas_interface
|
from db_layer.capturas_interface import capturas_interface
|
||||||
from db_layer.capturing_tasks_interface import capturing_interface
|
from db_layer.capturing_tasks_interface import capturing_interface
|
||||||
from core.config import refresher_delay
|
|
||||||
from core import my_logger
|
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
class Refresher:
|
class Refresher:
|
||||||
def start(self):
|
@staticmethod
|
||||||
|
def start() -> None:
|
||||||
|
"""
|
||||||
|
Execute main flow.
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
sleep(refresher_delay)
|
sleep(refresher_delay)
|
||||||
|
|
@ -28,12 +30,9 @@ class Refresher:
|
||||||
:param html: HTML del anuncio en string.
|
:param html: HTML del anuncio en string.
|
||||||
:return: True si esta dado de baja, False si no.
|
:return: True si esta dado de baja, False si no.
|
||||||
"""
|
"""
|
||||||
try:
|
if "anunciante" in html and "baja" in html:
|
||||||
if ":-|" in html or "El anunciante lo dio de baja" in html:
|
return True
|
||||||
return True
|
else:
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except TypeError:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue