Skip to content
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

提出一覧ページを見るのにログインが必要になった #23

Closed
kotatsugame opened this issue Apr 20, 2023 · 8 comments
Closed

Comments

@kotatsugame
Copy link
Owner

https://twitter.com/atcoder/status/1648939398241853440

@yupiteru
Copy link

yupiteru commented Jul 3, 2023

以下のようなログイン処理で提出ページの閲覧はできそうです。

【前提】環境変数に以下の値を設定しておく

  • ATCODER_ID
    • AtCoder にログインするためのID
  • ATCODER_PASSWORD
    • AtCoder にログインするためのパスワード
# Python Version: 3.x
import os
import sys
import time

import bs4
import requests


sess = requests.Session()

def get_html(url: str) -> bs4.BeautifulSoup:
    resp = sess.get(url)
    resp.raise_for_status()
    soup = bs4.BeautifulSoup(resp.content, 'lxml')
    time.sleep(0.5)
    return soup

# あらかじめ環境変数に設定したIDとパスワードを取得
atcoder_id = os.environ.get('ATCODER_ID')
atcoder_password = os.environ.get('ATCODER_PASSWORD')

# 一度ログインページを開き、csrf_tokenを取得しておく(ログイン時に必要)
csrf_token = get_html('https://atcoder.jp/login').find(name='input', attrs={'name': 'csrf_token'})['value']

# for debug
print("id:" + atcoder_id)
print("password:" + atcoder_password)
print("csrf_token:" + csrf_token)


# id, パスワード, csrf_token を使ってログイン
resp = sess.post('https://atcoder.jp/login', { 'username': atcoder_id, 'password': atcoder_password, 'csrf_token': csrf_token})

# for debug
print("login info:" + str(resp))

# 以降ログインしたアカウントで提出ページの取得ができる
print (get_html('https://atcoder.jp/contests/abc001/submissions'))

@kotatsugame
Copy link
Owner Author

kotatsugame commented Jul 4, 2023

ありがとうございます!実は問題点はもう二つほどあります:

  • ログインに自分のアカウントを使うのはアクセス制限的な意味で大丈夫か
  • 次はどの SNS で atgolfer を動かすか

後者は実際に Twitter が終焉してから考えればよいとして、前者が気になっています。AtCoderProblems がどうされているかとか、ご存じないでしょうか……
そういえば提出一覧をコード長でソートするクエリはかなり重いらしく、頻繁にタイムアウトするのでした。AtCoderProblems の API を使わせていただくのが安定するのかもしれません。

@yupiteru
Copy link

yupiteru commented Jul 4, 2023

AtCoderProblems がどうされているかとか

軽く聞いてみました。

自分の ID を使ってるみたいです。
今のところ 403 を返してくるケースは無いっぽいです。

AtCoder のアクセス制御は秒間1アクセスまで、みたいな感じのようで、
並列アクセスしなければ基本的には大丈夫そうです。

atgolfer においては、get_html のディレイを 1 秒とかに伸ばせば安全だと思います。

@yupiteru
Copy link

yupiteru commented Jul 4, 2023

開催中のコンテストに参加登録している場合がちょっと気になりますが、実装上 /submissions/me にアクセスしないので大丈夫かなと思っています。
過去のコンテスト一覧から取得しているので OK でした。

@kotatsugame
Copy link
Owner Author

返信遅れてすいません。

自分の ID を使ってるみたいです。
今のところ 403 を返してくるケースは無いっぽいです。

情報助かります!ただやっぱり orderBy=source_length は重いらしく結構な頻度で 500 が返ってきます。このリトライ回数をどうするかはちょっと考える必要がありますね

@kotatsugame
Copy link
Owner Author

#24 書いてみました。今 Twitter API のほうでアレでアレですが……

@kotatsugame
Copy link
Owner Author

投稿に成功したのでまあ多分大丈夫だと思います。マージしてデプロイします

@yupiteru
Copy link

yupiteru commented Jul 6, 2023

ありがとうございます!
お疲れさまです!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants