Skip to content
Permalink
Browse files

first commit

  • Loading branch information...
uejun committed Jun 6, 2019
0 parents commit ff7901d87c2b132c1ab408e461b60106e3579912
Showing with 97 additions and 0 deletions.
  1. +35 −0 README.md
  2. +4 −0 auth.json
  3. +57 −0 main.py
  4. +1 −0 requirements.txt
@@ -0,0 +1,35 @@
# YnuNetworkAuthKeeper

YNUネットワーク認証を定期的に自動で行うシステム

## PreRequirements

### ChromeDriver
```
brew cask install chromedriver
```

### Python

適当に仮想環境を設定してください.

```
pip install -r requirements.txt
```

### 認証情報の記載
auth.json
```
{
"id": "xxxx",
"password": "xxxx"
}
```

## 実行

```
$ python main.py
```
@@ -0,0 +1,4 @@
{
"id": "xxxx",
"password": "xxxx"
}
57 main.py
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
import json
import os
import time
from selenium import webdriver


def main():
print(os.path.abspath(__file__))
abs_dirpath = os.path.dirname(os.path.abspath(__file__))
auth_filepath = os.path.join(abs_dirpath, "auth.json")

try:
while True:
# YNUネットワーク認証IDとPasswordを認証jsonファイルより取得
with open(auth_filepath, 'r') as f:
auth_data = json.load(f)
ynu_id = auth_data["id"]
password = auth_data["password"]

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs", prefs)

# Chrome起動
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(10)
driver.set_page_load_timeout(30)

# YNUネットワーク認証
url = "https://na.ynu.ac.jp/"
driver.get(url)
time.sleep(1.5)

print(driver.current_url)
if driver.current_url == "https://na.ynu.ac.jp/www/login-success-page.html":
driver.close()
else:
driver.find_element_by_name("name").send_keys(ynu_id)
driver.find_element_by_name("pass").send_keys(password)
time.sleep(1)
driver.find_element_by_xpath('//input[@value="login"]').submit()
time.sleep(1)

# ブラウザを終了
driver.close()

time.sleep(11*60*60)
except KeyboardInterrupt:
try:
driver.close()
except:
pass


if __name__ == '__main__':
main()
@@ -0,0 +1 @@
selenium==3.141.0

0 comments on commit ff7901d

Please sign in to comment.
You can’t perform that action at this time.