-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
credential.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# bot-takarazuka | ||
|
||
## 使い方 | ||
|
||
1. credential.jsonにIDとパスワードを入力 | ||
|
||
```json | ||
{ | ||
"id": "[email protected]", | ||
"password": "YOUR_PASSWORD" | ||
} | ||
|
||
``` | ||
|
||
2. コマンド実行 | ||
|
||
```shell | ||
python3 run.php | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# ライブラリ読み込み | ||
import datetime | ||
import json | ||
import time | ||
|
||
from selenium import webdriver | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
|
||
|
||
def is_access_failed(driver) -> bool: | ||
if driver.title == "Sorry Page": | ||
return True | ||
|
||
elements = driver.find_elements(By.CLASS_NAME, "fc_red") | ||
|
||
if len(elements) > 0 and "ただいまアクセスが集中し、つながりにくい状態です。" in elements[0].text: | ||
return True | ||
|
||
return False | ||
|
||
|
||
# クロームの立ち上げ | ||
driver = webdriver.Chrome() | ||
wait = WebDriverWait(driver, 15) | ||
|
||
# ページ接続 | ||
driver.get( | ||
'https://www.takarazuka-ticket.com/mp/twjlg.do?md=1&ls=2&ul=https://www.takarazuka-ticket.com/rt/twjkl.do') | ||
|
||
# ログインフォーム | ||
login_id_form = wait.until(EC.element_to_be_clickable((By.ID, 'loginid_form'))) | ||
|
||
with open('credential.json') as f: | ||
d = json.load(f) | ||
|
||
login_id_form.send_keys(d['id']) | ||
driver.find_element(By.ID, 'password_form').send_keys(d['password']) | ||
|
||
login_button = wait.until(EC.element_to_be_clickable((By.ID, 'login_btn'))) | ||
login_button.click() | ||
|
||
# アクセスが失敗してたらreloadしなおす | ||
while True: | ||
time.sleep(5) | ||
now = datetime.datetime.now() | ||
if is_access_failed(driver): | ||
print("reload: %s", now) | ||
driver.refresh() | ||
else: | ||
print("not reload: %s", now) | ||
|
||
# 2時間終了を待つ | ||
# time.sleep(7200) | ||
|
||
# クロームの終了処理 | ||
# driver.close() |