From bffeef1b9f373ec04b7a5854e555fc6f9acc45a2 Mon Sep 17 00:00:00 2001 From: Park MinSuk <apark0907@ajou.ac.kr> Date: Fri, 23 Jun 2023 19:22:05 +0900 Subject: [PATCH] =?UTF-8?q?sw.py=20=EC=A0=95=EB=A6=AC=20+=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sw.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/sw.py b/sw.py index 2bd6b9c..ee51ea9 100644 --- a/sw.py +++ b/sw.py @@ -4,24 +4,25 @@ from time import sleep import csv -Ajou_student = [] -pages = 3 -for page in range(pages): - url = "https://solved.ac/api/v3/ranking/in_organization?organizationId=328" +Ajou_student = [] # 아주대학교 학생들 리스트 +pages = 3 # 받아올 페이지의 제한 +group_id = 328 # 아주대학교의 group_id 입니다. + +for page in range(pages): + url = "https://solved.ac/api/v3/ranking/in_organization?organizationId={group_id}" page_url = f"{url}&page={page+1}" cnt = requests.get(page_url) Tmp_Ajou_student = json.loads(cnt.content.decode("utf-8")).get("items") Ajou_student.extend([user.get("handle").strip() for user in Tmp_Ajou_student]) -def solved_problem(user_handle): # 유저 아이디를 입력하면 유저가 푼 문제 목록을 확인해볼수있습니다. +def solved_problem(user_handle): # 유저 아이디를 입력하면 유저가 푼 문제 목록을 return 하는 함수 url = f"https://solved.ac/api/v3/search/problem?query=s%40{user_handle}" - print(user_handle) cnt = json.loads(requests.get(url).content.decode("utf-8")) pages = (cnt.get("count") - 1) // 50 + 1 pid = [] for page in range(pages): - sleep(1) + sleep(1) # API 호출 횟수를 조절하기 위한 sleep 함수 page_url = f"{url}&page={page+1}" cnt = json.loads(requests.get(page_url).content.decode("utf-8")) problem_ = cnt.get("items") @@ -30,16 +31,14 @@ def solved_problem(user_handle): # 유저 아이디를 입력하면 유저가 print(f"[{user_handle}] {page}/{pages}") return pid - +limit = 15 pid = {} -for user in Ajou_student[:15]: +for user in Ajou_student[:limit]: user_problem = solved_problem(user) - print(user) for problem in user_problem: - pid[problem] = pid.get(problem, 0) + 1 -print(pid) + pid[problem] = pid.get(problem, 0) + 1 # pid에 problem이 있다면 +1하고, 없다면 1을 채워줍니다. -with open("top15_user_problem.csv", "w") as file: +with open(f"top{limit}_user_problem.csv", "w") as file: writer = csv.writer(file) for k, v in pid.items(): writer.writerow([k, v]) -- GitLab