Skip to content

Instantly share code, notes, and snippets.

@akunzai
Created March 7, 2024 04:03
Show Gist options
  • Save akunzai/8b8f55a9244713742d83b6e65738f256 to your computer and use it in GitHub Desktop.
Save akunzai/8b8f55a9244713742d83b6e65738f256 to your computer and use it in GitHub Desktop.

Fix Github ghost notification

Please generate Personal Access Token first

# create python virtual environment
python -m venv ghost

source ./ghost/bin/activate

pip install requests

python ./fix_github_ghost_notification.py
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