Skip to content

Instantly share code, notes, and snippets.

@hristo-joia
Last active February 1, 2024 15:38
Show Gist options
  • Select an option

  • Save hristo-joia/2b18fa90b8ce315ec3b6fe6591fbdbac to your computer and use it in GitHub Desktop.

Select an option

Save hristo-joia/2b18fa90b8ce315ec3b6fe6591fbdbac to your computer and use it in GitHub Desktop.
Delete all read notifications from your modrinth notification history.
#!/usr/bin/env python
import requests
import json
username = "" # Enter your modrinth username here
HEADERS = {
"Authorization": "" # Enter your authorisation token here
}
def get_notifs(username):
response = requests.get(
f"https://api.modrinth.com/v2/user/{username}/notifications", headers=HEADERS
)
if response.status_code == 404:
print("Error: user not found")
return 404
if response.status_code == 401:
print("Error: invalid authentication credentials")
return 401
arr = str(response.content.decode("UTF-8"))
arr = json.loads(arr)
return arr
def filter_notifs(arr):
notifs = []
for d in arr:
for k, v in d.items():
if k == "id":
notif = v
if k == "read":
if v:
notifs.append(notif)
return notifs
def delete_notifs(notifs):
requests.delete(
f"https://api.modrinth.com/v2/notifications?ids={json.dumps(notifs)}",
headers=HEADERS,
)
arr = get_notifs(username)
while arr == 404:
username = input("Please enter a valid username: ")
arr = get_notifs(username)
while arr == 401:
HEADERS["Authorization"] = input("Please enter a valid auth token: ")
arr = get_notifs(username)
notifs = filter_notifs(arr)
delete_notifs(notifs)
print(f"Cleared {len(notifs)} out of {len(arr)} notifications")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment