From 8b4a895cfb2a7b3108d882cc391db00c5eb78e1d Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Sat, 6 Jan 2024 19:09:45 +0100 Subject: [PATCH] create worker package --- models/ReserveResultPojo.py | 5 ++- request_sender.py | 86 +----------------------------------- workers/__init__.py | 0 workers/proxies_constants.py | 11 +++++ workers/sender.py | 80 +++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 86 deletions(-) create mode 100644 workers/__init__.py create mode 100644 workers/proxies_constants.py create mode 100644 workers/sender.py diff --git a/models/ReserveResultPojo.py b/models/ReserveResultPojo.py index 4b7fc3a..0d41ae1 100755 --- a/models/ReserveResultPojo.py +++ b/models/ReserveResultPojo.py @@ -119,9 +119,10 @@ class ReserveResultPojo: u'email': self.email, u'passport': self.passport, u'url': self.url, - u'sim_position': self.sim_position, - u'slot_position': self.slot_position, + # u'sim_position': self.sim_position, + # u'slot_position': self.slot_position, u'source_from': self.source_from, + u'hostName': self.source_from, u'created_at': self.created_at, u'store_type': self.store_type, u'accepted': self.accepted, diff --git a/request_sender.py b/request_sender.py index f784a6a..1d927aa 100644 --- a/request_sender.py +++ b/request_sender.py @@ -1,25 +1,11 @@ -import datetime import random import time -from http.cookies import SimpleCookie - -import requests from db.mongo_manager import MONGO_STORE_MANAGER from excel_reader import read_contacts -from models.ReserveResultPojo import ReserveResultPojo, PublishType from models.contact_pojo import ContactPojo from queue_message.receiver import Receiver - -FR_PROXY_MOBILE = { - 'http': 'http://7039778-mobile-country-FR:2ji8e3r0nh@89.39.106.148:14806', - 'https': 'http://7039778-mobile-country-FR:2ji8e3r0nh@89.39.106.148:14806' -} - -# FR_PROXY_MOBILE = { -# 'http': 'http://e99aff2d-409239:19elyiw1ge@93.190.141.102:31637', -# 'https': 'http://e99aff2d-409239:19elyiw1ge@93.190.141.102:31637' -# } +from workers.sender import Sender IPFIY = 'http://api.ipify.org' HERMES_REGISTER = "https://rendezvousparis.hermes.com/client/register" @@ -48,78 +34,10 @@ def filter_contacts(_contact_list: list) -> list: return _contact_list_to_book -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 = 'uWGIeylh-DjQFXI439Fc_ete5RcVA7eDsnQU' - 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: - response = requests.post(url=url, proxies=FR_PROXY_MOBILE, 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 - - def on_message(ch, method, properties, body): print(f" [x] Received {body}") sender = Sender(body.decode("UTF-8")) - contact_list = read_contacts('/Users/panlei/Desktop/yahoo_aol_valid_26-1.xlsx') + contact_list = read_contacts('/Users/panlei/Desktop/yahoo_aol_valid_26-2.xlsx') # remove already booked contacts sub_contact_list = filter_contacts(contact_list) random.shuffle(sub_contact_list) diff --git a/workers/__init__.py b/workers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/workers/proxies_constants.py b/workers/proxies_constants.py new file mode 100644 index 0000000..2b9cb0d --- /dev/null +++ b/workers/proxies_constants.py @@ -0,0 +1,11 @@ +FR_PROXY_MOBILE = { + 'http': 'http://7039778-mobile-country-FR:2ji8e3r0nh@89.39.106.148:14806', + 'https': 'http://7039778-mobile-country-FR:2ji8e3r0nh@89.39.106.148:14806' +} + +FR_PROXY_RES = { + 'http': 'http://e99aff2d-409239:19elyiw1ge@93.190.141.102:31637', + 'https': 'http://e99aff2d-409239:19elyiw1ge@93.190.141.102:31637' +} + +PROXY_LIST = [FR_PROXY_RES, FR_PROXY_MOBILE] \ No newline at end of file diff --git a/workers/sender.py b/workers/sender.py new file mode 100644 index 0000000..274be5b --- /dev/null +++ b/workers/sender.py @@ -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