Skip to content

AtCoder新サイトに対応 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
![サンプル画像](https://imgur.com/9T2Tg7W.png)

* ↑のような感じで、AtCoderの質問(Clarification)が来たらSlackに通知します。
* owner権限を持っている前提のコンテスト管理者用のツールのため、コンテスタントだと使えません
* AtCoder Beta版には対応していません
* Manager権限を持っている前提のコンテスト管理者用のツールのため、Contestantだと使えません
* 旧サイト(`https://xxx.contest.atcoder.jp`)の廃止に伴い、新サイト(`https://atcoder.jp/contests/xxx`)に対応しました

## 使い方

Expand All @@ -19,7 +19,7 @@ cp config_sample config
2. configファイルを以下の例に従って編集。

```
CONTEST_URL=https://jag2017autumn.contest.atcoder.jp # クラー通知したいコンテストのURL(Beta版には対応していません)
CONTEST_URL=https://atcoder.jp/contests/jag2017autumn/ # クラー通知したいコンテストのURL
ATCODER_ID=username # コンテストの管理権限を所持しているユーザのID
ATCODER_PASS=password # ユーザのパスワード
SLACK_HOOK_URL=https://hooks.slack.com/services/XXXX/XXXX/XXXX # slackのincoming webhook url ※1
Expand Down
2 changes: 1 addition & 1 deletion config_sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONTEST_URL=https://hogehoge.contest.atcoder.jp
CONTEST_URL=https://atcoder.jp/contests/<contest_name>/
ATCODER_ID=
ATCODER_PASS=
SLACK_HOOK_URL=
Expand Down
4 changes: 3 additions & 1 deletion login.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set -e
source ./config
curl -c ./cookiejar -F "name=${ATCODER_ID}" -F "password=${ATCODER_PASS}" "${CONTEST_URL}/login"
LOGIN_URL='https://atcoder.jp/login'
CSRF_TOKEN=$(curl -c ./cookiejar -s ${LOGIN_URL} | grep 'csrfToken' | cut -f 2 -d '"')
curl -b ./cookiejar -c ./cookiejar -X POST -F "csrf_token=${CSRF_TOKEN}" -F "username=${ATCODER_ID}" -F "password=${ATCODER_PASS}" "${LOGIN_URL}"
4 changes: 2 additions & 2 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set -e
source ./config
curl -s -b ./cookiejar "${CONTEST_URL}/clarifications" > ./clar.html
python3 ./read_clar.py ./clar.html ${CONTEST_URL} ./clar1.json
curl -s -b ./cookiejar "${CONTEST_URL%/}/clarifications" > ./clar.html
python3 ./read_clar.py ./clar.html ./clar1.json
if [[ -e ./clar0.json ]]; then
python3 ./diff_clar.py ./clar0.json ./clar1.json ./slack.sh
fi
Expand Down
44 changes: 24 additions & 20 deletions read_clar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@
import re
import sys

CONTEST_URL = sys.argv[2]
SAVE_PATH = sys.argv[3]

def func(s):
m = re.search(r"<a href=\"(.*)\">(.*)</a>", s)
return "<%s%s|%s>" % (CONTEST_URL, m.group(1), m.group(2))
SAVE_PATH = sys.argv[2]


data = []
with open(sys.argv[1], encoding="utf-8") as f:
a = re.findall(r"<tbody>.*?</tbody>", f.read(), re.S)
if not a:
tbody = re.findall(r"<tbody>.*?</tbody>", f.read(), re.S)
if not tbody:
print("<tbody> not found")
else:
assert len(a) == 1
a = re.findall(r"<tr>.*?</tr>", a[0], re.S)
for x in a:
b = re.findall(r"<td.*?</td>", x, re.S)
title = func(b[0])
user_name = func(b[1])
assert re.fullmatch(r"<td>.*</td>", b[2], re.S)
assert re.fullmatch(r"<td>.*</td>", b[3], re.S)
question = re.sub(r"<.*?>", "", b[2][4:-5]).replace("&#039;", "'")
response = re.sub(r"<.*?>", "", b[3][4:-5]).replace("&#039;", "'")
public = re.sub(r"<.*?>", "", b[4])
update_url = CONTEST_URL + re.search(r"<a href=\"(.*?)\">", b[7]).group(1)
assert len(tbody) == 1
rows = re.findall(r"<tr.*?</tr>", tbody[0], re.S)
for row in rows:
columns = re.findall(r"<td.*?</td>", row, re.S)

title = re.sub(r"\s+", " ", columns[0])[4:-5].strip()
if title == "":
title = "(指定なし)"
else:
m = re.search(r"<a href=\"(.*)\">(.*)</a>", title)
title = "<%s|%s>" % ("https://atcoder.jp" + m.group(1), m.group(2).strip())

m = re.search(r"<a href=\"(.*)\" .*\"><span.*>(.*)</span></a>.*<a.*", re.sub(r"\s+", " ", columns[1]))
user_name = "<%s|%s>" % ("https://atcoder.jp" + m.group(1), m.group(2))

assert re.fullmatch(r"<td>.*</td>", columns[2], re.S)
assert re.fullmatch(r"<td>.*</td>", columns[3], re.S)
question = re.sub(r"<.*?>", "", columns[2][55:-11]).replace("&#039;", "'")
response = re.sub(r"<.*?>", "", columns[3][55:-11]).replace("&#039;", "'")
public = re.sub(r"<.*?>", "", columns[4][4:-5])
update_url = "https://atcoder.jp" + re.search(r"<a href=\"(.*?)\">", columns[7]).group(1)

data.append({
"title": title,
Expand Down