Created
March 22, 2021 12:32
-
-
Save gormih/86f44b2d00380a1ff4a81c8e46c34375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from PIL import Image | |
from playsound import playsound | |
oauth_url = 'https://oauth.yandex.com/token' | |
client_id = 'iddddddd' | |
client_secret = 'secret' | |
username = '[email protected]' | |
password = 'passowrd' | |
def download_file(url, fname): | |
with requests.get(url, stream=True) as r: | |
r.raise_for_status() | |
with open(fname, 'wb+') as f: | |
for chunk in r.iter_content(chunk_size=8192): | |
# If you have chunk encoded response uncomment if | |
# and set chunk_size parameter to None. | |
# if chunk: | |
f.write(chunk) | |
data = { | |
'grant_type': 'password', | |
'client_id': client_id, | |
'client_secret': client_secret, | |
'username': username, | |
'password': password | |
} | |
headers = {'Content-Type': 'text/plain;charset=UTF-8', | |
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 YaBrowser/20.6.0.905 Yowser/2.5 Safari/537.36'} | |
while True: | |
resp = requests.post(oauth_url, data=data, headers=headers).json() | |
if 'x_captcha_key' in resp.keys(): | |
img_url = resp['x_captcha_url'] | |
voice_url = img_url.replace('image', 'voice') | |
# im = Image.open(io.BytesIO(requests.get(img_url).content)) | |
# im.show() | |
# playsound(io.BytesIO(requests.get(voice_url).content)) | |
fname = f'{resp["x_captcha_key"]}.mp3' | |
download_file(voice_url, fname) | |
playsound(fname) | |
data['x_captcha_answer'] = input(f'Введите капчу для ключа {resp["x_captcha_key"]}: ') | |
print(f"{img_url}, {voice_url}") | |
data['x_captcha_key'] = resp['x_captcha_key'] | |
print(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment