2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python + Docker + NotionAPI + Google DriveでAtCoderの問題を収集する環境を作る

Posted at

Github

概要

  • AtCoderの問題・解説ページをGoogleドライブで見れる環境を作る
  • iPadのGoogleドライブで, フォルダの中身をオフラインで使用可能にしておけば, 外でも勉強できる
    summary.png

何をするか

  • 指定したコンテストの問題・解説ページのスクリーンショットを撮影し, Googleドライブに保存する

  • AtCoder ProblemInformation APIから各問題のDifficultyを取得し,Difficultyごとに保存

drive_summary.png

  • Notionのデータベースにノートを用意する
    notion_db_summary.png

実行方法

  • 実行コマンド (例)

    • abc280からabc284までのA, B, C問題がダウンロードされる
python -m atcoder_offline --prefix abc --begin 280 --end 284 --problem a b c
  • --clear_doneオプションをつけることで,Notionのデータベースでstatus == Doneとした問題をGoogleドライブから削除できる

各種設定

.env

  • 必ず.env.example.json.envにリネームする

  • .envにはAPIトークンを保管するため, 絶対にgit管理しない

    • 代わりに.env.example.jsonをgit管理する

docker

  • docker-compose内のseleniumコンテナのイメージを次のように変更する

    • intelチップの場合,image:selenium/standalone-chromium
    • M1/M2チップ搭載のmacの場合,image:seleniarm/standalone-chromium

Goodleドライブ APIの有効化

Goodleドライブの保存先

フォルダ構成

  • フォルダ名は固定

  • 保存先のディレクトリをオフラインで使用可能にしておく

drive.png

フォルダIDの取得

  • env.jsonCOLOR_TO_DIRに,それぞれの色に対応するフォルダIDを設定する

  • フォルダIDは,フォルダを開いてURLを確認することで得られる

https://drive.google.com/drive/folders/<フォルダID>

Notion APIの有効化

  • https://www.notion.so/my-integrations からインテグレーションを作成し,トークンを取得

  • ******************の部分をコピーし,env.jsonTOKEN_NOTIONに割り当てる

notion_token.png

参考 (公式) https://developers.notion.com/docs/create-a-notion-integration

Notion データベースの用意

データベースの作成

  • プロパティにcontest, color, statusを持つデータベースを作成する
    notion_db.png

インテグレーションの接続

  • コネクトの追加から,作成したインテグレーションを追加する

結果

実行結果
result.png

statusの更新

before

after


参考

macの場合,ベースイメージをseleniumではなくseleniarmを使う (docker-compose)

Seleniumを使ってスクリーンショット

Googleドライブの操作

beautifulsoup

2
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?