-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_api.py
More file actions
43 lines (28 loc) · 939 Bytes
/
Copy pathgithub_api.py
File metadata and controls
43 lines (28 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
from fastapi import FastAPI
app = FastAPI()
class GithubAPI:
BASE_URL = 'https://api.github.com'
def get_user_info(self , username):
url = f'{self.BASE_URL}/users/{username}'
response = requests.get(url)
if response.status_code == 200:
return response.json()
return None
github = GithubAPI()
@app.get('/users/{username}')
async def profile(username: str):
user = github.get_user_info(username)
if user is None:
return {'error': 'User not found!'}
return {
"username": user["login"] or 'unknown',
"followers": user["followers"] or 'unknown',
"following": user["following"] or 'unknown',
"repos": user["public_repos"] or 'unknown',
"bio": user["bio"] or 'unknown',
"location": user["location"] or 'unknown',
"avatar": user["avatar_url"] or 'unknown',
'created account at': user['created_at'],
'last online': user['updated_at']
}