Skip to content
Snippets Groups Projects
Commit bffeef1b authored by Park MinSuk's avatar Park MinSuk
Browse files

sw.py 정리 + 주석

parent f3ba0542
No related branches found
No related tags found
No related merge requests found
......@@ -4,24 +4,25 @@ from time import sleep
import csv
Ajou_student = []
pages = 3
Ajou_student = [] # 아주대학교 학생들 리스트
pages = 3 # 받아올 페이지의 제한
group_id = 328 # 아주대학교의 group_id 입니다.
for page in range(pages):
url = "https://solved.ac/api/v3/ranking/in_organization?organizationId=328"
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])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment