1

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 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

I get the following error: TypeError: string indices must be integers on user_ids = [x['committer']['id'] for x in input_log if x['committer'].get('id')]
Would this have to do with me iterating over a dictionary as opposed to a list?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.