modLogic.py 1.4 KB

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