Files
appointment_tool/commandor_page.py
T

120 lines
4.4 KiB
Python

import asyncio
import subprocess
import time
import playwright
from playwright.async_api import async_playwright
from playwright.sync_api import sync_playwright
from pojo.contact_pojo import ContactPojo
# RDV_URL = "https://rendezvousparis.hermes.com/client/register"
RDV_URL = "file:///Users/lpan/Downloads/test_appointment.html"
# RDV_URL = "https://www.google.fr"
# RDV_URL = "https://api.ipify.org"
class CommandorPage:
def __init__(self):
pass
async def start_page(self, proxy, contact: ContactPojo):
# specifying an explicit component name
async with async_playwright() as pwright:
self.browser = await pwright.chromium.launch(headless=False, timeout=30000, proxy=proxy)
self.page = await self.browser.new_page(
user_agent="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Mobile Safari/537.36")
await self.page.goto(RDV_URL)
content = await self.page.content()
await self.setPhoneCountry()
await self.setPhoneNumber(contact.phone)
await self.setName(contact.last_name, contact.first_name)
await self.setEmail(contact.mail)
await self.setIdNumber(contact.passport)
await self.checkCgu()
await self.clickOnValidBtn()
# page.on('load', self.on_page_loaded)
print(content)
await asyncio.sleep(1000)
def on_page_loaded(self):
print("page loaded")
async def setPhoneCountry(self):
await self.page.evaluate("""()=>document.getElementById("phone_country").value = \"FR\" """)
async def setPhoneNumber(self, phoneNumber):
await self.page.evaluate("""(phoneNumber)=>document.getElementById("phone_number").value =phoneNumber""",
phoneNumber)
async def setName(self, lastName, firstName):
await self.page.evaluate("""(name)=> {
document.getElementById("surname").value = name.lastName;
document.getElementById("name").value = name.firstName}""", {'lastName': lastName, 'firstName': firstName})
async def setEmail(self, email):
await self.page.evaluate("""(email)=>document.getElementById("email").value = email""", email)
async def setIdNumber(self, id):
await self.page.evaluate(""" (id) => document.getElementById("passport_id").value = id""", id)
async def checkCgu(self):
await self.page.evaluate("""document.getElementById("cgu").checked = true;
document.getElementById("processing").checked = true""")
async def clickOnValidBtn(self):
await self.page.evaluate("""document.getElementsByClassName("btn")[0].click();""")
def clear_app_data(self):
pass
def send_otp(self, otp: str):
self.page.evaluate(""" (otp)=> document.getElementById("sms_code").value = otp""", otp)
def reset_air_plan_mode(self):
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell settings put global airplane_mode_on 1",
shell=True)
time.sleep(1)
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell am broadcast -a android.intent.action.AIRPLANE_MODE",
shell=True)
time.sleep(1)
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell settings put global airplane_mode_on 0",
shell=True)
time.sleep(1)
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell am broadcast -a android.intent.action.AIRPLANE_MODE",
shell=True)
time.sleep(10)
async def main():
contact = ContactPojo(phone_number="755667750", passport_number="5123456789", last_name="PAN", first_name="Lei",
mail="panleicim@gmail.com", ccid="", position=0)
page = CommandorPage()
await page.start_page(None, contact)
# task = asyncio.create_task(wait_for_otp())
# await task
async def wait_for_otp():
sec = input("Press Enter to continue...")
time.sleep(20)
print("input otp is: " + sec)
if __name__ == '__main__':
proxy = {
"server": "http://gw.ntnt.io:5959",
"username": "panleicim-cc-any-sid-1112",
"password": "M3PZAXgW5V27"
}
asyncio.gather(main(), wait_for_otp())
time.sleep(1000)