Created
June 20, 2023 11:11
-
-
Save airtower-luna/4f371c7d8799632ba5b9ed855039a484 to your computer and use it in GitHub Desktop.
Mark GitHub notifications as read
This file contains 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 json | |
import os | |
import requests | |
from datetime import datetime, timezone | |
NOTIFICATIONS = 'https://api.github.com/notifications' | |
token = os.environ['GH_TOKEN'] | |
s = requests.Session() | |
s.headers.update({ | |
'Authorization': f'Bearer {token}', | |
'Accept': 'application/vnd.github+json'}) | |
r = s.get(NOTIFICATIONS) | |
print(json.dumps(r.json(), indent=2)) | |
now = datetime.now(timezone.utc) | |
print(now.isoformat(timespec='seconds')) | |
r = s.put( | |
NOTIFICATIONS, | |
json={ | |
'last_read_at': now.isoformat(timespec='seconds'), | |
'read': True | |
}) | |
print(r.status_code) | |
for k, v in r.headers.items(): | |
print(f'{k}: {v}') | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment