create worker package
This commit is contained in:
@@ -119,9 +119,10 @@ class ReserveResultPojo:
|
|||||||
u'email': self.email,
|
u'email': self.email,
|
||||||
u'passport': self.passport,
|
u'passport': self.passport,
|
||||||
u'url': self.url,
|
u'url': self.url,
|
||||||
u'sim_position': self.sim_position,
|
# u'sim_position': self.sim_position,
|
||||||
u'slot_position': self.slot_position,
|
# u'slot_position': self.slot_position,
|
||||||
u'source_from': self.source_from,
|
u'source_from': self.source_from,
|
||||||
|
u'hostName': self.source_from,
|
||||||
u'created_at': self.created_at,
|
u'created_at': self.created_at,
|
||||||
u'store_type': self.store_type,
|
u'store_type': self.store_type,
|
||||||
u'accepted': self.accepted,
|
u'accepted': self.accepted,
|
||||||
|
|||||||
+2
-84
@@ -1,25 +1,11 @@
|
|||||||
import datetime
|
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from http.cookies import SimpleCookie
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from db.mongo_manager import MONGO_STORE_MANAGER
|
from db.mongo_manager import MONGO_STORE_MANAGER
|
||||||
from excel_reader import read_contacts
|
from excel_reader import read_contacts
|
||||||
from models.ReserveResultPojo import ReserveResultPojo, PublishType
|
|
||||||
from models.contact_pojo import ContactPojo
|
from models.contact_pojo import ContactPojo
|
||||||
from queue_message.receiver import Receiver
|
from queue_message.receiver import Receiver
|
||||||
|
from workers.sender import Sender
|
||||||
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'
|
|
||||||
# }
|
|
||||||
|
|
||||||
IPFIY = 'http://api.ipify.org'
|
IPFIY = 'http://api.ipify.org'
|
||||||
HERMES_REGISTER = "https://rendezvousparis.hermes.com/client/register"
|
HERMES_REGISTER = "https://rendezvousparis.hermes.com/client/register"
|
||||||
@@ -48,78 +34,10 @@ def filter_contacts(_contact_list: list) -> list:
|
|||||||
return _contact_list_to_book
|
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):
|
def on_message(ch, method, properties, body):
|
||||||
print(f" [x] Received {body}")
|
print(f" [x] Received {body}")
|
||||||
sender = Sender(body.decode("UTF-8"))
|
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
|
# remove already booked contacts
|
||||||
sub_contact_list = filter_contacts(contact_list)
|
sub_contact_list = filter_contacts(contact_list)
|
||||||
random.shuffle(sub_contact_list)
|
random.shuffle(sub_contact_list)
|
||||||
|
|||||||
@@ -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]
|
||||||
@@ -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