Created
July 10, 2018 15:24
-
-
Save tal95shah/c335b3e93cc9df5badd94702d2f6ba84 to your computer and use it in GitHub Desktop.
Github User data wrapper using dataclasses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from dataclasses import dataclass,field | |
| from dateutil import parser | |
| from datetime import datetime | |
| # GithubAPIWrapper | |
| @dataclass | |
| class GithubWrapper(object): | |
| 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 | |
| def __post_init__(self): | |
| if type(self.created_at) is str: | |
| self.created_at=parser.parse(self.created_at) | |
| if type(self.updated_at) is str: | |
| self.updated_at=parser.parse(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