はじめに
タスク管理ツールとしてMammothProjectというタスク管理アプリを使用しています。
さて、私の職場では日報が採用されており、やり残したタスクを書く項目があるのですが、なかなかめんどくさいのでタスク管理ツールのキャプチャを貼るようにしました。(後々webスクレイピングにしてもいいかもー)
そこでやっぱり自動化ですよね。
想定は
- ヘッドレスchromeでMammothProjectにログイン
- 自身のタスク一覧画面をキャプチャ
となります。
環境
- Python 3.7.3
- mac OS Mojave
後、当コードの実行にあたって以下サイトを参照してSeleniumを実行できる環境を用意しています。
https://qiita.com/memakura/items/20a02161fa7e18d8a693
コード
taskCapture.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import configparser
# chromeを準備
def initDriver():
# driverを定義
options = Options()
options.add_argument('--headless')
return webdriver.Chrome(options=options)
# 設定ファイル取得
def getIniFile():
iniFile = configparser.ConfigParser()
iniFile.read('./config.ini', 'UTF-8')
return iniFile
# ログイン
def login(driver,iniFile):
# マンモスプロジェクトにログイン
driver.get(iniFile.get('settings', 'URL'))
driver.find_element_by_id('user_email').send_keys(iniFile.get('user', 'name'))
driver.find_element_by_id('user_password').send_keys(iniFile.get('user', 'password'))
driver.find_element_by_name('button').click()
# スクリーンショットを撮る。
def screenCaputure(driver, iniFile):
# なんか狭かったので固定値を設定
# page_width = driver.execute_script('return document.body.scrollWidth')
page_width = 1400
page_height = driver.execute_script('return document.body.scrollHeight')
driver.set_window_size(page_width, page_height)
driver.save_screenshot(iniFile.get('user', 'download'))
# メイン処理
def main():
# chrome画面を準備
driver = initDriver()
# 設定ファイル取得
iniFile = getIniFile()
# ログイン
login(driver, iniFile)
# スクリーンキャプチャ
screenCaputure(driver, iniFile)
# 終了
driver.quit()
exit()
if __name__ == '__main__':
main()
config.ini
[settings]
URL : https://app.mmth.pro/mytask#/list
[user]
name : (ログインするメールアドレス)
password : (ログインするパスワード)
download : (好きなディレクトリ)/タスク.png
結果
画面の幅に改善点はあるものの、その他はいい感じ。
後Pythonを初めて触ってみましたが、手軽にかけていい感じー。