try to test record audio
This commit is contained in:
+254
File diff suppressed because one or more lines are too long
@@ -9,3 +9,4 @@ boto3~=1.21.13
|
|||||||
openpyxl==3.0.9
|
openpyxl==3.0.9
|
||||||
google-cloud-firestore==2.4.0
|
google-cloud-firestore==2.4.0
|
||||||
PySimpleGUI==4.60.0
|
PySimpleGUI==4.60.0
|
||||||
|
SpeechRecognition==3.8.1
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import random
|
||||||
|
# for recaptcha
|
||||||
|
import urllib
|
||||||
|
import pydub
|
||||||
|
from speech_recognition import Recognizer, AudioFile
|
||||||
|
import random
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class SolveCaptcha:
|
||||||
|
def __init__(self, page):
|
||||||
|
self.page = page
|
||||||
|
self.main_frame = None
|
||||||
|
self.recaptcha = None
|
||||||
|
|
||||||
|
def delay(self):
|
||||||
|
self.page.wait_for_timeout(random.randint(1, 3) * 1000)
|
||||||
|
|
||||||
|
def presetup(self):
|
||||||
|
name = self.page.locator(
|
||||||
|
"//iframe[@title='reCAPTCHA']").get_attribute("name")
|
||||||
|
self.recaptcha = self.page.frame(name=name)
|
||||||
|
|
||||||
|
self.recaptcha.click("//div[@class='recaptcha-checkbox-border']")
|
||||||
|
self.delay()
|
||||||
|
s = self.recaptcha.locator("//span[@id='recaptcha-anchor']")
|
||||||
|
if s.get_attribute("aria-checked") != "false": # solved already
|
||||||
|
return
|
||||||
|
|
||||||
|
# self.main_frame = self.page.frame(name=self.page.locator(
|
||||||
|
# "//iframe[contains(@src,'https://www.google.com/recaptcha/api2/bframe?')]").get_attribute("name"))
|
||||||
|
# self.main_frame.click("id=recaptcha-audio-button")
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
print("start to resolve captcha")
|
||||||
|
self.presetup()
|
||||||
|
tries = 0
|
||||||
|
while (tries <= 5):
|
||||||
|
self.delay()
|
||||||
|
try:
|
||||||
|
self.solve_captcha()
|
||||||
|
except Exception as e:
|
||||||
|
print("exception:")
|
||||||
|
print(e)
|
||||||
|
self.main_frame.click("id=recaptcha-reload-button")
|
||||||
|
else:
|
||||||
|
s = self.recaptcha.locator("//span[@id='recaptcha-anchor']")
|
||||||
|
if s.get_attribute("aria-checked") != "false":
|
||||||
|
self.page.click("id=recaptcha-demo-submit")
|
||||||
|
self.delay()
|
||||||
|
break
|
||||||
|
tries += 1
|
||||||
|
|
||||||
|
def solve_captcha(self):
|
||||||
|
print("solve_captcha()")
|
||||||
|
# self.main_frame.click(
|
||||||
|
# "//button[@aria-labelledby='audio-instructions rc-response-label']")
|
||||||
|
# href = self.main_frame.locator(
|
||||||
|
# "//a[@class='rc-audiochallenge-tdownload-link']").get_attribute("href")
|
||||||
|
#
|
||||||
|
# print("retrieve mp3 file")
|
||||||
|
# urllib.request.urlretrieve(href, "audio.mp3")
|
||||||
|
#
|
||||||
|
# sound = pydub.AudioSegment.from_mp3(
|
||||||
|
# "audio.mp3").export("audio.wav", format="wav")
|
||||||
|
#
|
||||||
|
# recognizer = Recognizer()
|
||||||
|
#
|
||||||
|
# recaptcha_audio = AudioFile("audio.wav")
|
||||||
|
# with recaptcha_audio as source:
|
||||||
|
# audio = recognizer.record(source)
|
||||||
|
# print("recognizer mp3 file")
|
||||||
|
#
|
||||||
|
# text = recognizer.recognize_google(audio)
|
||||||
|
# print("recognized text: " + text)
|
||||||
|
# self.main_frame.fill("id=audio-response", text)
|
||||||
|
# self.main_frame.click("id=recaptcha-verify-button")
|
||||||
|
# self.delay()
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
pass
|
||||||
|
# os.remove("audio.mp3")
|
||||||
|
# os.remove("audio.wav")
|
||||||
@@ -11,6 +11,7 @@ import params
|
|||||||
from params import PROXY_SERVER, PROXY_PASSWORD
|
from params import PROXY_SERVER, PROXY_PASSWORD
|
||||||
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
from pojo.ReserveResultPojo import ReserveResultPojo, PublishType
|
||||||
from pojo.contact_pojo import ContactPojo
|
from pojo.contact_pojo import ContactPojo
|
||||||
|
from workers.SolveCaptch import SolveCaptcha
|
||||||
|
|
||||||
RDV_URL = "https://rendezvousparis.hermes.com/client/register"
|
RDV_URL = "https://rendezvousparis.hermes.com/client/register"
|
||||||
|
|
||||||
@@ -92,6 +93,7 @@ class CommandorPage:
|
|||||||
self.setIdNumber(self.contact.passport)
|
self.setIdNumber(self.contact.passport)
|
||||||
#
|
#
|
||||||
self._checkCgu()
|
self._checkCgu()
|
||||||
|
self.click_recapcha_checkbox()
|
||||||
# wait for sms_code field
|
# wait for sms_code field
|
||||||
# self.clickOnValidBtn()
|
# self.clickOnValidBtn()
|
||||||
self.thread_event = e
|
self.thread_event = e
|
||||||
@@ -157,7 +159,7 @@ class CommandorPage:
|
|||||||
self.get_errors()
|
self.get_errors()
|
||||||
|
|
||||||
def on_document_loaded(self):
|
def on_document_loaded(self):
|
||||||
print("on_document_loaded called")
|
self.logger.info("on_document_loaded called")
|
||||||
|
|
||||||
def _setPhoneCountryAndStore(self):
|
def _setPhoneCountryAndStore(self):
|
||||||
try:
|
try:
|
||||||
@@ -261,6 +263,15 @@ class CommandorPage:
|
|||||||
def clear_app_data(self):
|
def clear_app_data(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def click_recapcha_checkbox(self):
|
||||||
|
captcha_solver = SolveCaptcha(self.page)
|
||||||
|
captcha_solver.start()
|
||||||
|
del captcha_solver
|
||||||
|
# checkbox = self.page.wait_for_selector(
|
||||||
|
# "#recaptcha-anchor")
|
||||||
|
# checkbox.click()
|
||||||
|
|
||||||
def fill_otp(self, otp: str):
|
def fill_otp(self, otp: str):
|
||||||
self.page.focus(OTP_FIELD_ID)
|
self.page.focus(OTP_FIELD_ID)
|
||||||
time.sleep(get_random_wait_time())
|
time.sleep(get_random_wait_time())
|
||||||
|
|||||||
Reference in New Issue
Block a user