Skip to content

Commit 8f3bc78

Browse files
Merge pull request kyuridenamida#13 from asi1024/without-login
いいね! Support kyuridenamida#12
2 parents 9010354 + 945cb50 commit 8f3bc78

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

AtCoderClient.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def prepare_procedure(argv):
7575
print("prepared %s!" % pid)
7676

7777

78-
def prepare_workspace(contestid):
79-
atcoder = AtCoder(AccountInformation.username, AccountInformation.password)
78+
def prepare_workspace(contestid, without_login):
79+
atcoder = AtCoder()
80+
if not without_login:
81+
atcoder.login(AccountInformation.username, AccountInformation.password)
8082

8183
while True:
8284
plist = atcoder.get_problem_list(contestid)
@@ -90,9 +92,14 @@ def prepare_workspace(contestid):
9092

9193

9294
if __name__ == "__main__":
93-
import sys
94-
if len(sys.argv) == 2:
95-
contestid = sys.argv[1]
96-
prepare_workspace(contestid)
97-
else:
98-
print("%s [contest_id]" % sys.argv[0])
95+
import argparse
96+
parser = argparse.ArgumentParser()
97+
parser.add_argument("contestid",
98+
help="contest ID")
99+
parser.add_argument("--without-login",
100+
action="store_true",
101+
help="download testdata without login")
102+
args = parser.parse_args()
103+
contestid = args.contestid
104+
without_login = args.without_login
105+
prepare_workspace(args.contestid, without_login)

core/AtCoder.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ class InputParseError(Exception):
2121
class AtCoder:
2222

2323
def __init__(self, username=None, password=None):
24+
self.cj = http.cookiejar.CookieJar()
25+
26+
self.opener = urllib.request.build_opener(
27+
urllib.request.HTTPCookieProcessor(self.cj))
28+
29+
def login(self, username=None, password=None):
2430
if username is None:
2531
username = input('AtCoder username: ')
2632

2733
if password is None:
2834
password = getpass.getpass('AtCoder password: ')
2935

30-
self.cj = http.cookiejar.CookieJar()
31-
32-
self.opener = urllib.request.build_opener(
33-
urllib.request.HTTPCookieProcessor(self.cj))
3436
postdata = {
3537
'name': username,
3638
'password': password

0 commit comments

Comments
 (0)