add result_pojo.py

This commit is contained in:
2024-02-08 00:25:04 +01:00
parent de2059435e
commit 83871f8e4b
6 changed files with 32 additions and 20 deletions
+10 -9
View File
@@ -8,8 +8,9 @@ import requests
from db.mongo_manager import MONGO_STORE_MANAGER
from models.LinkPojo import LinkPojo
from models.result_pojo import RequestResult
from queue_message.CookiesPublisher import CookiesPublisher, REQUEST_DATA_QUEUE_TEST
from queue_message.appointmentrequestsendor import QUEUE_HOST, REQUEST_DATA_QUEUE, credentials
from queue_message.appointmentrequestsender import QUEUE_HOST, REQUEST_DATA_QUEUE, credentials
from workers.proxies_constants import PROXY_LIST_FR
DOUBLE_MESSAGE = "Une demande de rendez-vous a déjà été enregistrée avec ces coordonnées"
@@ -41,7 +42,7 @@ class LinkValidator(threading.Thread):
self.channel.basic_consume(queue=self.queue_to_listen, auto_ack=False, on_message_callback=callback)
self.channel.start_consuming()
def send_request(self, linkPojo: LinkPojo) -> bool:
def send_request(self, linkPojo: LinkPojo) -> RequestResult:
self.cookie.load(self.cookie_str)
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Mobile Safari/537.36',
@@ -78,7 +79,7 @@ class LinkValidator(threading.Thread):
# upload the cookie to queue
self.cookiesPublisher.publish_body(new_coolies_str)
self.cookie_str = new_coolies_str
return True
return RequestResult.SUCCESS
elif DOUBLE_MESSAGE in _content:
print(response.url)
MONGO_STORE_MANAGER.link_validated_for_result(response.url, linkPojo, is_duplicated=True)
@@ -93,14 +94,14 @@ class LinkValidator(threading.Thread):
# upload the cookie to queue
self.cookiesPublisher.publish_body(new_coolies_str)
self.cookie_str = new_coolies_str
return True
return RequestResult.SUCCESS
else:
return False
return RequestResult.UNKNOWN
else:
return False
return RequestResult.BLOCKED
except Exception as error:
print(error)
return False
return RequestResult.PROXY_ERROR
def on_message(self, ch, method, properties, body):
print(f" [x] Received {body}")
@@ -116,8 +117,8 @@ class LinkValidator(threading.Thread):
# if not is_already_sent(con):
print(con.email)
can_continue = self.send_request(con)
if not can_continue:
print("cannot continue, skip")
if can_continue == RequestResult.BLOCKED:
print("cannot continue, blocked, then skip")
break
else:
time.sleep(random.randint(2, 5))
+5 -4
View File
@@ -7,6 +7,7 @@ import requests
from db.mongo_manager import MONGO_STORE_MANAGER
from models.ReserveResultPojo import ReserveResultPojo, PublishType
from models.result_pojo import RequestResult
from queue_message.CookiesPublisher import CookiesPublisher
from workers.proxies_constants import PROXY_LIST_FR
@@ -43,7 +44,7 @@ class Sender:
def get_csrf(self):
pass
def send_request(self, url, contact: ContactPojo, csrf: str = None):
def send_request(self, url, contact: ContactPojo, csrf: str = None) -> RequestResult:
if csrf is None:
if self._csrf is None:
_csrf = '8Bs2dBwb-nHONOzo9Tei2CcMZglEfsRqUz8E'
@@ -86,9 +87,9 @@ class Sender:
# upload the cookie to queue
self.cookiesPublisher.publish_body(new_coolies_str)
self.cookie_str = new_coolies_str
return True
return RequestResult.SUCCESS
else:
return False
return RequestResult.BLOCKED
except Exception as Error:
print(Error)
return False
return RequestResult.PROXY_ERROR