lbry_notifications.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # This file will provide a simple LBRY notification system on
  2. # user's system. GPLv3 or later. By J.Y.Amihud.
  3. from getpass import getpass
  4. import requests
  5. auth_token = getpass("Token: ")
  6. # Function to recieve notifications
  7. def fetch_notifications(auth_token):
  8. notifications = requests.post("https://api.odysee.com/notification/list", data={"auth_token":auth_token}).json()
  9. if "data" in notifications:
  10. return notifications["data"]
  11. else:
  12. return []
  13. # System Notification Function
  14. def notify(title="LBRY Notification", text=""):
  15. from subprocess import Popen
  16. import os
  17. Popen(["notify-send", "-i", os.getcwd()+"/Odysee.png","-a", "Odysee Notification!", title, text])
  18. #Fetching once
  19. notifications = fetch_notifications(auth_token)
  20. for i in notifications:
  21. if not i["is_read"]:
  22. print()
  23. par = i["notification_parameters"]
  24. if not "comment" in i["type"]:
  25. notify(par["device"]["title"], par["device"]["name"])
  26. print(par["device"]["title"], par["device"]["name"])
  27. else:
  28. notify(par["device"]["title"], par["dynamic"]["comment"])
  29. print(par["device"]["title"], par["dynamic"]["comment"])
  30. import time
  31. # Fetch more
  32. while True:
  33. time.sleep(2) # Wait 2 seconds
  34. more = fetch_notifications(auth_token)
  35. for i in more:
  36. if i not in notifications:
  37. print()
  38. par = i["notification_parameters"]
  39. if not "comment" in i["type"]:
  40. notify(par["device"]["title"], par["device"]["name"])
  41. print(par["device"]["title"], par["device"]["name"])
  42. else:
  43. notify(par["device"]["title"], par["dynamic"]["comment"])
  44. print(par["device"]["title"], par["dynamic"]["comment"])
  45. notifications.append(i)