LoginSignup
85
47

More than 1 year has passed since last update.

AtCoderの提出を取得してGitHubの芝を生やすコマンドラインツールを作った

Last updated at Posted at 2020-03-24

procon-gardener

概要

AtCoderの提出から自動的にコードを取得して、ローカルリポジトリに保存するprocon-gardenerというツールを作りました。
モチベーションとしては競技プログラミングの問題は解いて、もりもりコードは書けるけどGitHubのアクティビティ(芝)がゼロで評価を受けづらい人のために作りました。

ツールではACコードの自動取得とリポジトリへのコミットは行いますが、pushは行いませんので各自で行ってください。

インストール方法

インストールするにはGoが必要です。

go install github.com/togatoga/procon-gardener@latest

サポート環境

  • Linux
  • macOS

Windowsでは動作確認してませんがサポートしたいのでどなたか動作確認していただけると嬉しいです。

使い方

アーカイブ先のレポジトリをprocon-archiveを用意しました。

1. 設定ファイルの初期化

必要な設定ファイルの作成を行います。procon-gardener initを実行してください。

% procon-gardener init  
2020/03/21 17:18:36 Initialize your config...
2020/03/21 17:18:36 Initialized your config at  /home/togatoga/.procon-gardener/config.json

2. 設定ファイルの編集

初期化した設定ファイルは以下のとおりです。設定ファイルを直接編集もしくはprocon-gardener editで編集することができます。
EDITORの環境変数が設定されていれば、EDITORに設定されているエディタで開きます。そうでなければOS依存のopenコマンドで開きます。

{
	"atcoder": {
		"repository_path": "",
		"user_id": "",
		"user_email": ""
	}
}
  • repository_path アーカイブ先のディレクトリを指定してください
  • user_id アーカイブ対象のユーザーIDを入力してください
  • user_email repository_pathGitリポジトリの場合、git commit時のメールアドレスに指定されます

user_emailをGitHubの登録メールアドレスに設定しないとGitHubのアクティビティには反映されません。
今回は以下のように設定ファイルを編集しました。

{
	"atcoder": {
		"repository_path":"/home/togatoga/src/github.com/togatoga/procon-archive",
		"user_id": "togatoga",
		"user_email": "togasakitogatoga+github@gmail.com"
	}
}

3. ソースコードのアーカイブ

procon-gardener archiveを実行すれば自動的にファイルがアーカイブされます。 コミットの時間は提出した時間を使っています。
AtCoderへの負荷対策のため1提出につき1.5秒sleepを行っています、AC数が多い人はしばらくお待ちください。
途中で処理の切断やキャンセルしても、既にアーカイブされたコードへのアーカイブ処理は行いません。

% procon-gardener archive                                 
2020/03/21 21:19:37 Archiving 1186 code...
2020/03/21 21:19:38 archived the code at  /home/togatoga/src/github.com/togatoga/procon-archive/atcoder.jp/abc133/abc133_d/Main.rs
Main.rs
2020/03/21 21:19:39 archived the code at  /home/togatoga/src/github.com/togatoga/procon-archive/atcoder.jp/abc148/abc148_e/Main.rs
Main.rs
2020/03/21 21:19:40 archived the code at  /home/togatoga/src/github.com/togatoga/procon-archive/atcoder.jp/abc134/abc134_d/Main.rs
Main.rs
2020/03/21 21:19:41 archived the code at  /home/togatoga/src/github.com/togatoga/procon-archive/atcoder.jp/abc115/abc115_d/Main.rs
Main.rs
2020/03/21 21:19:42 archived the code at  /home/togatoga/src/github.com/togatoga/procon-archive/atcoder.jp/agc033/agc033_a/Main.rs
Main.rs
2020/03/21 21:19:43 archived the code at  /home/togatoga/src/github.com/togatoga/procon-archive/atcoder.jp/abc141/abc141_d/Main.rs
Main.rs
2020/03/21 21:19:44 archived the code at  /home/togatoga/src/github.com/togatoga/procon-archive/atcoder.jp/ddcc2020-qual/ddcc2020_qual_d/Main.rs
Main.rs

$ cd /home/togatoga/src/github.com/togatoga/procon-archive/
$ git log
commit 412134182e09ab0e165e3499020bcebd80ecfe6d (HEAD -> master)
Author: togatoga <togasakitogatoga+github@gmail.com>
Date:   Sun Mar 15 15:08:28 2020 +0900

    [AC] abc141 abc141_d

commit d8d36f6cc5ca35ab433b5e6fbabe7ca4e4f7f8bd
Author: togatoga <togasakitogatoga+github@gmail.com>
Date:   Sun Mar 15 16:54:37 2020 +0900

    [AC] agc033 agc033_a

commit abf4779970804c3fd6fe8bf2d7b2ac02a15e3d34
Author: togatoga <togasakitogatoga+github@gmail.com>
Date:   Sun Mar 15 18:29:50 2020 +0900

    [AC] abc115 abc115_d

commit 2615058a482a7f7589d900fd5c84ff8a5ebfc871
Author: togatoga <togasakitogatoga+github@gmail.com>
Date:   Mon Mar 16 09:42:47 2020 +0900

    [AC] abc134 abc134_d

commit b84a716762fd4df6df19121b5599b526f2fdba89
Author: togatoga <togasakitogatoga+github@gmail.com>
Date:   Wed Mar 18 22:12:23 2020 +0900

    [AC] abc148 abc148_e

commit 7f905746a102190f054430e696da8ab742cffb5c
Author: togatoga <togasakitogatoga+github@gmail.com>
Date:   Fri Mar 20 06:30:19 2020 +0900

    [AC] abc133 abc133_d

アーカイブ先のディレクトリでgit pushでリモート先を更新しましょう。

% cd /home/togatoga/src/github.com/togatoga/procon-archive
[master][togatoga] ~/src/github.com/togatoga/procon-archive
% git push origin HEAD
Enumerating objects: 2346, done.
Counting objects: 100% (2346/2346), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2215/2215), done.
Writing objects: 100% (2345/2345), 317.15 KiB | 2.01 MiB/s, done.
Total 2345 (delta 799), reused 0 (delta 0)
remote: Resolving deltas: 100% (799/799), done.
To github.com:togatoga/procon-archive
   ee2253b..9210fe6  HEAD -> master
[master][togatoga] ~/src/github.com/togatoga/procon-archive

push前

Screenshot from 2020-03-24 11-25-49.png

push後

Screenshot from 2020-03-24 11-26-03.png

AtCoderの問題を解いてGitHubの芝を生やしていきましょう。

バグ報告&要望

要望、バグ報告などはGitHubのissueもしくは@togatoga_まで連絡ください。

85
47
2

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
85
47