modLogic.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Содержит всю логику работы с ботами"""
  2. from typing import Any
  3. import json
  4. import requests
  5. class Logic():
  6. """Логика монитора"""
  7. def __init__(self, app: Any) -> None:
  8. self.app = app
  9. self.port = "18061" # Для прода -- 18060
  10. if app.isProd:
  11. self.port = "18060"
  12. def add_new_bot(self, login: str, _pass: str) -> None:
  13. """Добавляет нового бота на бото ферму"""
  14. data: dict[str, str] = {
  15. "login": login,
  16. "pass": _pass,
  17. "is_auto": "true",
  18. }
  19. res = requests.post("http://localhost:"+self.port +
  20. "/list_bot/add", data=data, timeout=2.0)
  21. print(f"Logic.add_new_bot(): result={res}")
  22. self.app.gui.winMain.update_list_bot()
  23. def get_list_bot(self):
  24. """Возвращает список ботов"""
  25. res = requests.get("http://localhost:"+self.port+"/list_bot/get",
  26. timeout=2.0)
  27. print(f"Logic.add_new_bot(): result={res.text}")
  28. content = json.loads(res.content)
  29. return content
  30. def get_stat_bot(self, name: str):
  31. """Возвращает статистику бота"""
  32. data = {
  33. "name": name,
  34. }
  35. res = requests.post("http://localhost:" +
  36. self.port+"/bot/stat", data=data, timeout=2.0)
  37. print(f"Logic.get_stat_bot(): result={res.text}")
  38. content = json.loads(res.content)
  39. return content