create worker package
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import datetime
|
||||
import random
|
||||
import time
|
||||
from http.cookies import SimpleCookie
|
||||
from models.contact_pojo import ContactPojo
|
||||
import requests
|
||||
|
||||
from db.mongo_manager import MONGO_STORE_MANAGER
|
||||
from models.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||
from workers.proxies_constants import PROXY_LIST
|
||||
|
||||
|
||||
class Sender:
|
||||
|
||||
def __init__(self, cookie_str):
|
||||
self.store_type = "random"
|
||||
self.cookie = SimpleCookie()
|
||||
# self.cookie_str = 'datadome=~pxdHFAvsQl2rvDrTzhPgCHxu~4TBcePTTE~Cy8Rgol6oMRc11gA02VRp0Z3uEDUszCjacubNu7vbfQCh27gz8RC10u_325pt_gsMmJh1ScGvOofVJiVAbEKvSEUjd82;policy=accepted;app.sig=PhjmDkq_dI49pADppDNKxpLe_G4;app=eyJmbGFzaCI6e30sImNhY2hlZmxhc2giOltdLCJjc3JmU2VjcmV0IjoiYnRodHNYU1lvdnl4RzVGakpGRDZsQ0JtIn0=;lang=fr;'
|
||||
self.cookie_str = cookie_str
|
||||
self.cookie.load(self.cookie_str)
|
||||
|
||||
def publish_message_to_queue(self, contact: ContactPojo, status: PublishType, url: str):
|
||||
# create the message
|
||||
if url == "https://rendezvousparis.hermes.com/client/welcome":
|
||||
return
|
||||
id = url.split("/")[-1]
|
||||
result = ReserveResultPojo(type=status, phone=contact.phone, message=status.value, url=url,
|
||||
firstName=contact.first_name, lastName=contact.last_name, email=contact.mail,
|
||||
passport=contact.passport, ccid=contact.ccid)
|
||||
result.id = id
|
||||
result.store_type = self.store_type
|
||||
result.created_at = time.strftime("%H:%M:%S", time.localtime())
|
||||
collection_name = str(datetime.date.today())
|
||||
MONGO_STORE_MANAGER.insert_reserve_result(collection_name=collection_name, reserve=result)
|
||||
|
||||
def send_request_for_list(self, contact_list: list):
|
||||
pass
|
||||
|
||||
def get_csrf(self):
|
||||
pass
|
||||
|
||||
def send_request(self, url, contact: ContactPojo):
|
||||
csrf = '5tHIY0Tf-AEKRQB7dbM7-_OIh7pZG_HdLsAk'
|
||||
headers = {'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Mobile Safari/537.36',
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
|
||||
'Cookie': self.cookie_str, 'Referer': 'https://rendezvousparis.hermes.com/client/register',
|
||||
'Sec-Fetch-Mode': 'navigate',
|
||||
'Sec-Fetch-Dest': 'document',
|
||||
'Accept-Language': 'fr-FR,fr;q=0.6'}
|
||||
data = {'check': '', '_csrf': csrf, 'prefer': '',
|
||||
'surname': contact.last_name.capitalize(), 'name': contact.first_name.capitalize(),
|
||||
'phone_country': "FR", 'phone_number': contact.phone, 'email': contact.mail,
|
||||
'passport_id': contact.passport, 'processing': 'on', 'cgu': 'on'}
|
||||
print(data)
|
||||
try:
|
||||
proxy_to_use = random.choice(PROXY_LIST)
|
||||
print(proxy_to_use)
|
||||
response = requests.post(url=url, proxies=proxy_to_use, verify=False, headers=headers, data=data,
|
||||
timeout=15)
|
||||
print(response.status_code)
|
||||
if response.status_code == 200:
|
||||
# add to mongodb
|
||||
print(response.text)
|
||||
print(response.url)
|
||||
self.publish_message_to_queue(contact, status=PublishType.SUCCESS, url=response.url)
|
||||
cookies_to_set = response.headers['set-cookie']
|
||||
self.cookie.load(cookies_to_set)
|
||||
new_cookies = {k: v.value for k, v in self.cookie.items()}
|
||||
new_coolies_str = ""
|
||||
for key in new_cookies:
|
||||
new_coolies_str = new_coolies_str + key + "=" + new_cookies[key] + ";"
|
||||
print(new_coolies_str)
|
||||
self.cookie_str = new_coolies_str
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception as Error:
|
||||
print(Error)
|
||||
return False
|
||||
Reference in New Issue
Block a user