Skip to content

Instantly share code, notes, and snippets.

@ratulotron
Last active April 21, 2020 01:44
Show Gist options
  • Save ratulotron/0aa974967ded413f3a0213078620b741 to your computer and use it in GitHub Desktop.
Save ratulotron/0aa974967ded413f3a0213078620b741 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Script to get Github info using API"""
import requests
import dateutil
from datetime import date
def main():
# add any number of usernames here
users = ['kennethreitz', 'mitsuhiko', 'jkbrzt', 'nvbn', 'donnemartin']
# main URL that doesn't get changed
baseurl = "https://api.github.com/users/"
# Which JSON properties we want to catch
properties = ['name', 'id', 'html_url', 'public_repos', 'created_at']
# date and time right now
now = date.today()
# run loop through all the users
for username in users:
# make API url with Github username
current_page = baseurl + username
# take response from the url
response = requests.get(current_page)
# conversion to human readable format
page_info = response.json()
# print all the properties
for property in properties:
print("{}: {}".format(property, page_info[property]))
# date of creation
date = dateutil.parser.parse(page_info["created_at"])
# age calculated from date of creation
age = (now.year - date.year)
print("age: {}".format(age))
print('')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment