1
votes

I am using the GitHub API to pull JSON data regarding commits on a repository.

Link to JSON file: https://api.github.com/repos/ErinBailey/cs399-social/commits

I am trying to to grab all the "id"s of users that committed to a project. How would I go about doing that? Right now I see the structure of the JSON file being sha/author/id.

So far my code is:

r = requests.get('https://api.github.com/repos/ErinBailey/cs399-social/commits', auth=('cs399contributions', 'contributions399'))

input_log = json.loads(r.text)
print(json.dumps(input_log, indent=4))
user_ids = [x for x in input_log if x['sha/commit/author/id'] > '0']
output_json = json.dumps(user_ids,indent=4)
print output_json
1

1 Answers

3
votes

Here is my code.

import requests
import json

r = requests.get('https://api.github.com/repos/ErinBailey/cs399-social/commits',
                 auth=('cs399contributions', 'contributions399'))

input_log = json.loads(r.text)
user_ids = [x['committer']['id'] for x in input_log if x['committer'].get('id')]
output_json = json.dumps(user_ids, indent=4)
print output_json