Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Gnimuc/ba577e5052d8b36653445cc11cf53ee2 to your computer and use it in GitHub Desktop.
Save Gnimuc/ba577e5052d8b36653445cc11cf53ee2 to your computer and use it in GitHub Desktop.
Mark GitHub notifications as read
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