我正在做我的大学作业项目。但我无法使用 github api 找到这些数据: 登录:他们的 Github 用户 ID 姓名:他们的全名 公司:他们工作的公司。清理公司名称。至少确保: 它们被修剪掉了空白 前导 @ 符号被删除(注意:仅删除第一个符号) 它们被转换为大写 地点:他们所在的城市 电子邮件:他们的电子邮件地址 可雇用:他们是否愿意被雇用 简介:关于他们的简短简介 public_repos:他们拥有的公共存储库的数量 关注者:他们拥有的关注者数量 关注:他们关注的人数 created_at:他们加入 Github 的时间 下面在我使用的代码中给出并获取 json 文件
json
import requests
import
query = "location:Bengaluru+followers:>100"
url = f"https://api.github.com/search/users?q={query}&sort=followers&order=desc"
response = requests.get(url)
data = response.json() # Parse the JSON response
formatted_json = json.dumps(data, indent=4) # Convert the JSON object to a formatted string
# Save the formatted JSON string to a file
F = open("user_data.json", "w")
F.write(formatted_json)
F.close()
我想找到使用 GITHUB REST API 询问的所有列的值
这是获取用户详细信息的简单代码(正如您提到的),请按照代码的注释进行解释,
"""
Remember GitHub has a Rate limit for user endpoints which is 100 queries per day for unauthenticated users,
if you want more than a thousand then use GitHub pat token with API for better results with more queries
just add this header, {
"Authorization": "Bearer {Token is here}"
}
API doc: https://docs.github.com/en/rest/quickstart?apiVersion=2022-11-28
"""
import requests
import json
url = 'https://api.github.com/search/users?q=location:Bengaluru+followers:>100'
resp = requests.get(url).json()
count = resp['total_count']
ranges = int(count / 30 + 1) #each page contains 30 results so we need to adjust the range value for loops
for i in range(1, ranges):
get_search = requests.get(f'https://api.github.com/search/users?q=location:Bengaluru+followers:>100&page={i}').json()
for i in get_search['items']:
name_u = i['login']
get_details = requests.get(f'https://api.github.com/users/{name_u}').json() #this is the user endpoint where user data will be fetched from
name = [f"ID: {get_details['id']}", f"Login: {get_details['login']}", f"Full Name: {get_details['name']}", f"Company: {get_details['company']}", f"Location: {get_details['location']}", f"Email: {get_details['email']}", f"Bio: {get_details['bio']}", f"Twitter username: {get_details['twitter_username']}", f"Public repo: {get_details['public_repos']}", f"Public gist: {get_details['public_gists']}", f"Follower: {get_details['followers']}", f"Following: {get_details['following']}", f"Account Created: {get_details['created_at']}"]
print(name)
['ID: 547147', 'Login: knadh', 'Full Name: Kailash Nadh', 'Company: Zerodha', 'Location: Bengaluru', 'Email: None', 'Bio: Hobbyist developer | CTO @zerodha | Volunteer @fossunited @rainmatter-foundation @indic-archive ', 'Twitter username: None', 'Public repo: 67', 'Public gist: 15', 'Follower: 9576', 'Following: 0', 'Account Created: 2011-01-04T15:32:55Z']
['ID: 12962887', 'Login: sadanandpai', 'Full Name: Sadanand Pai', 'Company: Atlassian', 'Location: Bengaluru', 'Email: None', 'Bio: Frontend Engineer | UI Dev | Learner', 'Twitter username: sadanand_pai', 'Public repo: 44', 'Public gist: 2', 'Follower: 2825', 'Following: 8', 'Account Created: 2015-06-19T06:35:46Z']
['ID: 29688323', 'Login: DeekshithSN', 'Full Name: Deekshith SN', 'Company: None', 'Location: Bengaluru', 'Email: None', 'Bio: A DevOps engineer with a knack for Automation and a proven track record in maintaining and administering DevOps process.\r\n', 'Twitter username: deekshithsn', 'Public repo: 69', 'Public gist: 4', 'Follower: 1730', 'Following: 1', 'Account Created: 2017-06-25T11:11:21Z']
['ID: 34368930', 'Login: collabnix', 'Full Name: Collabnix', 'Company: @collabnix', 'Location: Bengaluru', 'Email: None', "Bio: Collabnix is a popular blogging site and DevOps community founded by Docker Captain Ajeet Singh Raina. It's a DevOps community of 9.6k Slack members.", 'Twitter username: collabnix', 'Public repo: 268', 'Public gist: 16', 'Follower: 1657', 'Following: 1', 'Account Created: 2017-12-08T09:28:02Z']
['ID: 9478845', 'Login: probelalkhan', 'Full Name: Belal Khan', 'Company: Simplified Coding', 'Location: Bengaluru, India', 'Email: None', 'Bio: Belal Khan is an experienced technologist with a passion for developing innovative solutions. ', 'Twitter username: probelalkhan', 'Public repo: 157', 'Public gist: 0', 'Follower: 1571', 'Following: 0', 'Account Created: 2014-10-31T09:42:00Z']
['ID: 22263782', 'Login: krishnadey30', 'Full Name: Krishna Kumar Dey', 'Company: SpotDraft', 'Location: Bengaluru', 'Email: None', "Bio: Senior-SDE SpotDraft | Ex-SDE Amazon Luxembourg | GSoC'20 Mentor @ Chapel | GSoC'19 @ Chapel | Software Developer ", 'Twitter username: krishnadey30', 'Public repo: 33', 'Public gist: 18', 'Follower: 1539', 'Following: 15', 'Account Created: 2016-09-17T20:09:40Z']
['ID: 19903539', 'Login: Shubham0812', 'Full Name: Shubham Kr. Singh', 'Company: iOS Developer @ Dailyrounds / Marrow', 'Location: Bengaluru,Karnataka', 'Email: None', 'Bio: iOS developer by profession. Loves iOS development, traveling, and solving problems. Also a UI / UX enthusiast.\r\n', 'Twitter username: shubham_iosdev', 'Public repo: 61', 'Public gist: 61', 'Follower: 1437', 'Following: 6', 'Account Created: 2016-06-13T08:30:04Z']
['ID: 77569653', 'Login: SamirPaulb', 'Full Name: Samir Paul', 'Company: National Institute of Technology Durgapur', 'Location: Bengaluru, Karnataka, India', 'Email: None', "Bio: NIT Dgp ECE'24 | Competitive Programmer | Back-End Developer | Former Intern at NITI Aayog", 'Twitter username: SamirPaulb', 'Public repo: 65', 'Public gist: 18', 'Follower: 1299', 'Following: 98', 'Account Created: 2021-01-17T09:54:08Z']
请告诉我这是否是您想要的