-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path10-my_github.py
More file actions
executable file
·31 lines (26 loc) · 822 Bytes
/
Copy path10-my_github.py
File metadata and controls
executable file
·31 lines (26 loc) · 822 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
#!/usr/bin/python3
"""
module to print ones github id
One will need GH PAT for this
"""
from requests import get
from sys import argv
from requests.auth import HTTPBasicAuth
def get_github_id(username: str, tokken: str) -> str:
"""
get the user id of a github user
Args:
username (str): github handle
tokken (str): the personal access tokken
"""
headers = {
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": "Bearer {}".format(tokken),
"User-Agent": "I am the Cavalry"
}
auth = HTTPBasicAuth(username, tokken)
response = get("https://api.github.com/user", headers=headers, auth=auth)
return response.json().get('id')
if __name__ == "__main__":
print(get_github_id(argv[1], argv[2]))