-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_tracker.py
More file actions
39 lines (32 loc) · 1.24 KB
/
github_tracker.py
File metadata and controls
39 lines (32 loc) · 1.24 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
import requests
import os
# 1. The Key (Authentication)
TOKEN = os.getenv("GITHUB_PAT")
HEADERS = {
"Authorization": f"Bearer {TOKEN}",
"Accept": "application/vnd.github.v3+json"
}
def check_notifications():
if not TOKEN:
print("❌ Error: GITHUB_PAT environment variable is not set. See README.md file for more instruction. ")
return
# 2. The Request (Making the Call)
url = "https://api.github.com/notifications"
response = requests.get(url, headers=HEADERS)
# 3. The Delivery (Checking if it worked and getting the JSON)
if response.status_code == 200:
notifications = response.json()
# 4. The Translation (Parsing the Data)
if not notifications:
print("🎉 You have no unread notifications!")
else:
print(f"📫 You have {len(notifications)} unread notifications:\n")
for item in notifications:
repo_name = item['repository']['full_name']
issue_title = item['subject']['title']
print(f"- [{repo_name}] {issue_title}")
else:
print(f"❌ Failed to connect. GitHub said: {response.status_code}")
print(response.text)
if __name__ == "__main__":
check_notifications()