Skip to content

Instantly share code, notes, and snippets.

@tal95shah
Created July 10, 2018 15:17
Show Gist options
  • Select an option

  • Save tal95shah/d2d19d2359b57e14c94bd6858733937d to your computer and use it in GitHub Desktop.

Select an option

Save tal95shah/d2d19d2359b57e14c94bd6858733937d to your computer and use it in GitHub Desktop.
Github's User data API Wrapper Old Way
import requests
from dateutil import parser
from datetime import datetime
# GithubAPIWrapper
class GithubWrapper(object):
def __init__(self,login: str,
id: int,
node_id: str,
avatar_url: str,
gravatar_id: str,
url: str,
html_url: str,
followers_url: str,
following_url: str,
gists_url: str,
starred_url: str,
subscriptions_url: str,
organizations_url: str,
repos_url : str,
events_url: str,
received_events_url: str,
type: str,
site_admin: bool,
name: str,
company: str,
blog: str,
location: str,
email: str,
hireable: bool,
bio: str,
public_repos: int,
public_gists: int,
followers: int,
following: int,
created_at: datetime,
updated_at: datetime
):
self.node_id=node_id
self.avatar_url=avatar_url
self.gravatar_id=gravatar_id
self.url=url
self.html_url=html_url
self.followers_url=followers_url
self.following_url=following_url
self.gists_url=gists_url
self.starred_url=starred_url
self.subscriptions_url=subscriptions_url
self.organizations_url=organizations_url
self.repos_url=repos_url
self.events_url=events_url
self.received_events_url=received_events_url
self.type=type
self.site_admin=site_admin
self.name=name
self.company=company
self.blog=blog
self.location=location
self.email=email
self.hireable=hireable
self.bio=bio
self.public_repos=public_repos
self.public_gists=public_gists
self.followers=followers
self.following=following
self.created_at=created_at
self.updated_at=updated_at
if isinstance(self.created_at,str):
self.created_at=parser.parse(self.created_at)
if isinstance(self.updated_at,str):
self.updated_at=parser.parse(self.updated_at)
def __repr__(self):
return """{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}
\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}
\n{}\n{}\n{}\n{}\n{}\n{}\n{}""".format(self.node_id,
self.avatar_url,
self.gravatar_id,
self.url,
self.html_url,
self.followers_url,
self.following_url,
self.gists_url,
self.starred_url,
self.subscriptions_url,
self.organizations_url,
self.repos_url,
self.events_url,
self.received_events_url,
self.type,
self.site_admin,
self.name,
self.company,
self.blog,
self.location,
self.email,
self.hireable,
self.bio,
self.public_repos,
self.public_gists,
self.followers,
self.following,
self.created_at,
self.updated_at)
if __name__ == '__main__':
req = requests.get("https://api.github.com/users/tal95shah")
json = req.json()
wrapper = GithubWrapper(**json)
print(wrapper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment