videopc_api.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. from os import system
  3. from fastapi import FastAPI
  4. api = FastAPI()
  5. with open("/etc/videopc_api_key", "r", encoding="utf-8") as api_file_reader:
  6. SECRET = api_file_reader.read().strip()
  7. @api.get("/" + SECRET + "/test_connection")
  8. async def test_connection():
  9. # TODO: check if daemons are running
  10. return {"api_online": 1}
  11. @api.get("/" + SECRET + "/input/pulpit")
  12. def switch_to_pulpit_in():
  13. system("hyprctl dispatch workspace 1")
  14. return {"success": 1}
  15. @api.get("/" + SECRET + "/input/rtmp")
  16. def switch_to_rtmp_in():
  17. system("hyprctl dispatch workspace 2")
  18. return {"success": 1}
  19. @api.get("/" + SECRET + "/input/black_screen")
  20. def switch_to_blackscreen():
  21. system("hyprctl dispatch workspace 3")
  22. return {"success": 1}
  23. @api.get("/" + SECRET + "/power/suspend")
  24. def suspend_videopc():
  25. system("systemctl suspend")
  26. return {"success": 1}
  27. @api.get("/" + SECRET + "/power/shutdown")
  28. def shutdown_videopc():
  29. system("shutdown now")
  30. return {"success": 1}
  31. @api.get("/" + SECRET + "/power/reboot")
  32. def reboot_videopc():
  33. system("reboot")
  34. return {"success": 1}