-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_repos.py
More file actions
32 lines (26 loc) · 1.09 KB
/
Copy pathpython_repos.py
File metadata and controls
32 lines (26 loc) · 1.09 KB
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
import requests
#显示星级最高的储存库。
# 执行API调用并储存响应。
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
headers = {'Accept': 'application/vnd.github.v3+json'}
r = requests.get(url, headers=headers)
print(f"状态代码: {r.status_code}")
# 将API响应赋给一个变量。
response_dict = r.json()
print(f"存储库总数: {response_dict['total_count']}")
# 探索有关仓库的信息。
repo_dicts = response_dict['items']
print(f"已返回存储库: {len(repo_dicts)}")
# 研究第一个仓库。
repo_dict = repo_dicts[0]
print("\n关于第一个存储库的选定信息:")
print(f"名称:{repo_dict['name']}")
print(f"所有者: {repo_dict['owner']['login']}")
print(f"评级: {repo_dict['stargazers_count']}")
print(f"储存库: {repo_dict['html_url']}")
print(f"创建时间: {repo_dict['created_at']}")
print(f"最后一次更新的时间: {repo_dict['updated_at']}")
print(f"描述: {repo_dict['description']}")
#print(f"\nKeys: {len(repo_dict)}")
#for key in sorted(repo_dict.keys()):
# print(key)