-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (44 loc) · 1.4 KB
/
main.py
File metadata and controls
55 lines (44 loc) · 1.4 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import json
import http.client
def user_name() -> str:
"""
check the user name if it exist will be return
"""
args = sys.argv
if len(args) != 2:
print("Usage: python3 main.py <username>")
sys.exit()
return args[1]
def get_latest_events(username: str) -> None:
headers = {
"Host": "api.github.com",
"User-Agent": "python-http-client",
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28"
}
conn = http.client.HTTPSConnection("api.github.com")
# in python3.9 > if i write the headers directly in the parameter it will give me error
# from the server (its bug in http.client)
conn.request("GET", f"/users/{username}/events", headers=headers)
response = conn.getresponse()
data = response.read()
dictData = json.loads(data.decode())
print("\n==== GitHub Activity for USERNAME ====")
for x, i in enumerate(dictData, 1):
print(f"[{x}]")
for j in i:
if j == "type":
print(f"Event: {i[j]}")
elif j == "repo":
print(f"Repo: {i[j]['name']}")
elif j == "created_at":
print(f"Date: {i[j]}")
print("----------------------------")
conn.close()
if __name__ == "__main__":
try:
user = user_name()
get_latest_events(user)
except Exception:
print("API failures")