forked from OpenHUTB/carla_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scores.py
67 lines (51 loc) · 1.91 KB
/
scores.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
import argparse
argparser = argparse.ArgumentParser(
description='Involvement Degree')
argparser.add_argument(
'-t', '--token',
help='your personal github access token')
args = argparser.parse_args()
# 替换为你的个人访问令牌(可选,但推荐)
TOKEN = args.token
headers = {
'Authorization': f'token {TOKEN}',
'Accept': 'application/vnd.github.v3+json'
}
owner = 'OpenHUTB' # 替换为仓库所有者
repo = 'carla_cpp' # 替换为仓库名称
# 初始化统计字典
issue_counts = {}
comment_counts = {}
page = 1
while True:
url = f'https://api.github.com/repos/{owner}/{repo}/issues?state=all&per_page=100&page={page}'
# 需要把代理关掉,否则报错(原因不明):urllib3.exceptions.MaxRetryError: HTTPSConnectionPool
response = requests.get(url, headers=headers)
issues = response.json()
if not issues:
break
for issue in issues:
# 过滤掉 Pull Requests
if 'pull_request' in issue:
continue
# 统计提问者
user = issue['user']['login']
issue_counts[user] = issue_counts.get(user, 0) + 1
# 获取 Issue 的评论
comments_url = issue['comments_url']
comments_response = requests.get(comments_url, headers=headers)
comments = comments_response.json()
for comment in comments:
commenter = comment['user']['login']
comment_counts[commenter] = comment_counts.get(commenter, 0) + 1
page += 1
sorted_issue_counts = dict(sorted(issue_counts.items(), key=lambda item: item[1], reverse=True))
sorted_comment_counts = dict(sorted(comment_counts.items(), key=lambda item: item[1], reverse=True))
# 输出结果
print("提问次数:")
for user, count in sorted_issue_counts.items():
print(f"{user}: {count}")
print("\n回答次数:")
for user, count in sorted_comment_counts.items():
print(f"{user}: {count}")