Guest User

Untitled

a guest
Jul 1st, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. from pypresence import Presence
  2. import time
  3. import psutil
  4. import pynvml
  5.  
  6. time.sleep(1)
  7.  
  8. pynvml.nvmlInit()
  9.  
  10. client_id =
  11. #Пример client_id = 1107349645656588412
  12. RPC: Presence = Presence(client_id)
  13. ButtonsList = [
  14. {
  15. "label": "GitHub",
  16. "url": "https://github.com/zxc"
  17. },
  18. {
  19. "label": "zxc.gg",
  20. "url": "https://zxc.gg"
  21. }
  22. ]
  23.  
  24. RPC.connect()
  25.  
  26. device_count = pynvml.nvmlDeviceGetCount()
  27. if device_count == 0:
  28. print("Video not found")
  29. has_video_card = False
  30. else:
  31. has_video_card = True
  32.  
  33. while True:
  34. time.sleep(1)
  35. ram_percent=psutil.virtual_memory().percent
  36. cpu_percent=psutil.cpu_percent()
  37.  
  38. if has_video_card:
  39. device_count = pynvml.nvmlDeviceGetCount()
  40. gpu_utilization = ''
  41. for i in range(device_count):
  42. handle = pynvml.nvmlDeviceGetHandleByIndex(i)
  43. gpu_utilization += f"{pynvml.nvmlDeviceGetUtilizationRates(handle).gpu / 1:.1f}% "
  44. else:
  45. gpu_utilization = ''
  46. # здесь отоброжение в приложение
  47. RPC.update(details=f"CPU: {cpu_percent}% GPU: {gpu_utilization} RAM: {ram_percent}%",
  48. large_image='https://media.tenor.com/gg.gif',
  49. large_text='3.14',
  50. buttons=ButtonsList,
  51. small_image='https://cdn3.emoji.gg/gg.png',
  52. )
  53.  
  54. pynvml.nvmlShutdown()
Add Comment
Please, Sign In to add comment