我需要循环提交并从GitHub API获取名称,日期和消息信息。
https://api.github.com/repos/droptable461/Project-Project-Management/commits
我有很多不同的东西,但我一直卡在字符串索引必须是整数错误:
def git():
#name , date , message
#https://api.github.com/repos/droptable461/Project-Project-Management/commits
#commit { author { name and date
#commit { message
#with urlopen('https://api.github.com/repos/droptable461/Project Project-Management/commits') as response:
#source = response.read()
#data = json.loads(source)
#state = []
#for state in data['committer']:
#state.append(state['name'])
#print(state)
link = 'https://api.github.com/repos/droptable461/Project-Project-Management/events'
r = requests.get('https://api.github.com/repos/droptable461/Project-Project-Management/commits')
#print(r)
#one = r['commit']
#print(one)
for item in r.json():
for c in item['commit']['committer']:
print(c['name'],c['date'])
return 'suc'
需要得到提交者,日期和他们的消息的人。
item['commit']['committer']
是一个字典对象,因此行:
for c in item['commit']['committer']:
正在转换字典键。
由于您在字符串(字典键)上调用[]
,因此您收到错误。
相反,代码看起来应该更像:
def git():
link = 'https://api.github.com/repos/droptable461/Project-Project-Management/events'
r = requests.get('https://api.github.com/repos/droptable461/Project-Project-Management/commits')
for item in r.json():
for key in item['commit']['committer']:
print(item['commit']['committer']['name'])
print(item['commit']['committer']['date'])
print(item['commit']['message'])
return 'suc'