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

provide functions about sessions as a library #636

Merged
merged 2 commits into from
Dec 17, 2019
Merged

provide functions about sessions as a library #636

merged 2 commits into from
Dec 17, 2019

Conversation

kmyk
Copy link
Member

@kmyk kmyk commented Dec 16, 2019

#480 (comment)

onlinejudge._implementation.utils のなかからいくつか onlinejudge.utils に移した

  • get_default_session with_cookiejar
  • default_cookie_path なども移した (with_cookiejar した結果から取れちゃうし、いっしょにあると便利だろうので)
  • 関数名はとりあえずそのまま、module の名前は onlinejudge.session という手もあるが細かく切るよりひとつにまとめた方がなんとなく楽かな、ぐらいの気持ちです。より良いのが思い付いたら提案してください

@yosupo06 これはあなたの目的のためによさそうですか? ところで atcoder-tools 並に高機能でかつ AtCoder 以外にも対応してるラッパーはほしいので、期待しています

Copy link
Contributor

@kawacchu kawacchu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コードはよさそうです。

@fukatani
Copy link
Contributor

PRありがとうございます!
競プロIDEでも使ってる奴があるので私にもレビューさせてください。

@fukatani
Copy link
Contributor

使っているのはdefault_cookie_path, with_cookiejar, new_session_with_our_user_agentでした。

@@ -353,6 +353,10 @@ def get_service(self) -> AtCoderService:
return AtCoderService()

def list_problem_data(self, *, session: Optional[requests.Session] = None) -> List['AtCoderProblemData']:
"""
:raises Exception: if logging in is required to see the tasks page
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:raises Exception: if logging in is required to see the tasks page
:raises NotLoggedInError: if logging in is required to see the tasks page

Copy link
Member Author

@kmyk kmyk Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotLoggedInError は飛ばなくて HTTPError みたいなやつになるはず (未確認) です。なのでたぶん Exception で正しい

Copy link
Contributor

@fukatani fukatani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kmyk
Copy link
Member Author

kmyk commented Dec 17, 2019

@fukatani 確認ですが、new_session_with_our_user_agent は今回は公開してないですが大丈夫ですか?
ちなみに、この関数はいかにも内部っぽいしほぼ requests.Session なので、そちらではこれを自前で呼んで User-Agent は rujaion/0.10.3 みたいに設定するのがよいと (私は) 考えています。

@fukatani
Copy link
Contributor

fukatani commented Dec 17, 2019

おっと、見逃してました。
あまり良くないんじゃないかなと思いつつ、しばらくはユーザーエージェントを一致させたいです。
rujaionでログインしてojで提出したい時、ojとユーザーエージェントが変わるとsubmitできないコンテストがあるためです。

ただ、ojで公開しないのは仕方がない感じはします。
なので、IDEの方で今まで通りの実装を使います。

@kmyk kmyk merged commit 2ebd3b0 into master Dec 17, 2019
@yosupo06
Copy link
Contributor

(merge後で恐縮ですが、)私もfukunatiさんと同じ3つを使ってました 3つめはget_default_sessionに置き換えれば問題なさそうなので、問題ありません ありがとうございます!

@kmyk kmyk deleted the feature/session branch January 21, 2020 18:24
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

Successfully merging this pull request may close these issues.

4 participants