stream_messages.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # This script will take messages send in the stream and give me to look at them.
  2. # GPLv3 or Later (C) J.Y.Amihud 2021
  3. import websocket # to install this use 'sudo pip3 install websocket-client'
  4. import json
  5. import os
  6. claim_id = input("Listen to claim: ")
  7. def on_message(wsapp, message):
  8. comment = "Some Error!"
  9. person = "Anonymous"
  10. support = 0
  11. print()
  12. print(message)
  13. print()
  14. try:
  15. m = json.loads(message)
  16. m = m["data"]
  17. comment = m["comment"]["comment"].replace("\n", " ").replace("'", "*")
  18. person = m["comment"]["channel_name"]
  19. support = m["comment"]["support_amount"]
  20. except Exception as e:
  21. print("ERROR!", e)
  22. os.system("notify-send -a 'Odysee LiveChat' '"+person+" "+str(support)+" LBC' '"+comment+"'")
  23. print()
  24. print(person)
  25. print(support)
  26. print(comment)
  27. print()
  28. wsapp = websocket.WebSocketApp("wss://comments.lbry.com/api/v2/live-chat/subscribe?subscription_id="+claim_id, on_message=on_message)
  29. wsapp.run_forever()