Untitled
unknown
python
a year ago
5.2 kB
1
Indexable
Never
import requests, datetime, random from faker import Faker from utils import methods # Initalize all clients faker_client: object = Faker() subway_stores = ["32456", "37656", "44974", "30106", "41713"] class StartSubway: def __init__(self) -> None: self.requests_session = requests.Session() self.headers = { 'authority': 'subwaylistens.com', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'accept-language': 'en-GB,en;q=0.9', 'cache-control': 'max-age=0', 'content-type': 'application/x-www-form-urlencoded', 'origin': 'https://subwaylistens.com', 'sec-ch-ua': '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'document', 'sec-fetch-mode': 'navigate', 'sec-fetch-site': 'same-origin', 'sec-fetch-user': '?1', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36', } self.requests_session.get("https://subwaylistens.com/") self.get_session_cookie() def get_session_cookie(self) -> None: """Init method that uses the request session to get global cookie""" cookies: dict = self.requests_session.cookies.get_dict() self.session_id: str = cookies['subwaylistens'] def validate_request_person( self ) -> None: email: str = methods.generate_email() first_name: str = faker_client.first_name() last_name: str = faker_client.last_name() local_headers = self.headers local_headers['referer'] = 'https://subwaylistens.com/?subwaylistens&mkt=en-GB&priv=110&con=110&tou=110&lang=en_GB' self.requests_session.post(f"https://subwaylistens.com/?{self.session_id}", data={ 'is_embedded': 'false', 'lang': 'en_GB', 'stay_main-pager': '0', 'nodeId': 'survey1', 'ballotVer': '2', 'currentPage': '0', 'defPgrAction': 'next', 'spl_q_subway_customer_email_txt': email, 'spl_q_subway_confirm_email_address_txt': email, 'spl_q_subway_customer_first_name_txt': first_name, 'spl_q_subway_customer_last_name_txt': last_name, 'forward_main-pager': 'Begin Survey', }, headers=local_headers ) self.validate_store_request() def validate_store_request( self ) -> None: """Method to send a validation request to subway with the store and transaction info""" local_headers = self.headers local_headers['referer'] = f'https://subwaylistens.com/?{self.session_id}' x = self.requests_session.post(f"https://subwaylisens.com/{self.session_id}", data = { 'is_embedded': 'false', 'stay_main-pager': '1', 'nodeId': 'survey1', 'ballotVer': '3', 'currentPage': '1', 'defPgrAction': 'next', 'spl_q_subway_receipt_restaurant_number_txt': '37656-0', 'cal_q_subway_receipt_transaction_date_date': methods.get_date(), 'dd_q_subway_receipt_hour_of_day_enum': '2', 'dd_q_subway_receipt_transaction_minute_enum': '1', 'spl_q_subway_receipt_transaction_id_txt': f'1/A-{random.randint(100000, 999999)}', 'forward_main-pager': 'Next' }, headers=local_headers ) print(x.text) self.send_survey_results() def send_survey_results( self ) -> None: local_headers = self.headers local_headers['referer'] = f'https://subwaylistens.com/?{self.session_id}' store_request = self.requests_session.post(f"https://subwaylisens.com/{self.session_id}", data = { 'is_embedded': 'false', 'stay_main-pager': '2', 'nodeId': 'survey1', 'ballotVer': '4', 'currentPage': '2', 'defPgrAction': 'next', 'onf_q_subway_osat_satisfaction_web_scale_5': '5', 'onf_q_subway_taste_quality_of_the_meal_web_scale_5': '5', 'onf_q_subway_speed_of_service_web_scale_5': '5', 'onf_q_subway_experience_with_staff_web_scale_5': '5', 'onf_q_subway_cleanliness_of_restaurant_web_scale_5': '5', 'spl_q_subway_ltr_comment': '', 'onf_q_subway_likely_to_return_scale_11': '10', 'onf_q_subway_ltr_likely_scale_11': '10', 'forward_main-pager': 'Finish', }, headers=local_headers ) print(store_request.text) StartSubway().validate_request_person()