Skip to content

Commit

Permalink
bot-takarazuka (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkiken authored Jun 25, 2023
1 parent 2644689 commit 06dacb4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions bot-takarazuka/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
credential.json
19 changes: 19 additions & 0 deletions bot-takarazuka/README.md
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
```
58 changes: 58 additions & 0 deletions bot-takarazuka/run.py
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()

0 comments on commit 06dacb4

Please sign in to comment.