You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.6 KiB
107 lines
3.6 KiB
from bs4 import BeautifulSoup
|
|
import mechanize
|
|
import requests
|
|
import time
|
|
import random, string
|
|
import os
|
|
from retrying import retry
|
|
|
|
def register_submit(mailaddress):
|
|
br = mechanize.Browser()
|
|
br.set_handle_robots(False)
|
|
|
|
br.open("https://cloud.voicetext.jp/webapi/api_keys/new")
|
|
|
|
br.select_form(action="/webapi/api_keys/confirm")
|
|
#フォーム選択
|
|
|
|
br["api_key[name]"] = "長谷川亮太"
|
|
br["api_key[company]"] = "個人"
|
|
br["api_key[email]"] = mailaddress
|
|
br.find_control(id="api_key_api_purpose_ids_1").get(id="api_key_api_purpose_ids_1").selected = True
|
|
br.find_control(id="api_key_accept_license").get(id="api_key_accept_license").selected = True
|
|
br.submit()
|
|
#個人情報を適当に
|
|
|
|
br.select_form(action="/webapi/api_keys")
|
|
br.submit(name="commit")
|
|
#確定ボタンをsubmit
|
|
print("submitted")
|
|
|
|
|
|
@retry
|
|
def email_scrape(mailaddress):
|
|
token = ""
|
|
r = requests.get("https://generator.email/"+mailaddress)
|
|
mailtext = r.text
|
|
|
|
soupject = BeautifulSoup(mailtext,"html.parser")
|
|
|
|
plist = soupject.find_all('p')
|
|
p = [s for s in plist if "VoiceText" in s.text][0].text.splitlines()
|
|
#ここのコードの解説。まずfind_allで<p>タグをすべて抽出しています。
|
|
#その後、s for s in plistでfor文により配列を一要素ずつまわし、
|
|
#if "voicetext" in で部分一致を判定しています。
|
|
#s.textでテキストをstringとして取得しています。
|
|
#その後、該当したものが配列として帰ってくるので、[0]のもののtextを再度取得してpに代入
|
|
#そして最後にsplitlines()をし、文字列を改行でsplitしています。
|
|
token = p[p.index("です。") - 2 ]
|
|
#「です。」の完全一致を検索、それに-2する形でtokenを抽出。
|
|
print(token)
|
|
return token
|
|
|
|
def main():
|
|
token = ""
|
|
if os.path.exists("token.txt"):
|
|
print("token.txt was found")
|
|
try:
|
|
with open("token.txt") as f:
|
|
token = f.read().rstrip("\n")
|
|
except Exception as e:
|
|
print(e)
|
|
else:
|
|
print("No exists token.txt get token")
|
|
|
|
randomtext = ''.join([random.choice(string.ascii_letters + string.digits) for i in range(8)])
|
|
mailaddress = randomtext + "soranoirohanani@ncpine.com"
|
|
print(mailaddress)
|
|
#メアドを適当に
|
|
|
|
register_submit(mailaddress)
|
|
|
|
print("https://generator.email/"+mailaddress)
|
|
#generator.emailのURLを表示
|
|
|
|
token = email_scrape(mailaddress)
|
|
|
|
try:
|
|
with open("token.txt",mode="w") as f:
|
|
f.write(token)
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
try:
|
|
with open("speaktexts.txt") as f:
|
|
speaktexts = f.readlines()
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
for speaktext in speaktexts:
|
|
filename = speaktext.rstrip("\n") + ".wav"
|
|
print(filename)
|
|
|
|
r = requests.post(url="https://api.voicetext.jp/v1/tts",params={"text":speaktext,"speaker":"show","pitch":"150"},auth=(token,""))
|
|
#API説明…https://api.voicetext.jp/v1/tts
|
|
#パラメータについて
|
|
#speaker = 話し手、無能ボイスの場合は"show"
|
|
#pitch = ピッチ、無能ボイスの場合は150s
|
|
#詳しくは公式ドキュメントを参考されたし -> https://cloud.voicetext.jp/webapi/docs/api
|
|
|
|
try:
|
|
with open(filename, 'xb') as saveFile:
|
|
saveFile.write(r.content)
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
main()
|