authors.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from enum import Enum
  2. from typing import List
  3. from dataclasses import dataclass
  4. class AutorType(Enum):
  5. SC = 'soundcloud'
  6. @dataclass
  7. class Author:
  8. id: int
  9. username: str
  10. info: str
  11. url: str
  12. type: AutorType
  13. class Authors:
  14. def __init__(self) -> None:
  15. self.authors = []
  16. def add_author(self, name: str, info: str, url: str) -> int:
  17. author_id = len(self.authors)+1
  18. self.authors.append(
  19. Author(
  20. id=author_id,
  21. username=name,
  22. info=info,
  23. url=url,
  24. type=AutorType.SC))
  25. return author_id
  26. def get_all(self) -> List[Author]:
  27. return self.authors
  28. def get_user_by_name(self, name: str) -> Author:
  29. for a in self.authors:
  30. if a.username == name:
  31. return a
  32. return Author(666, 'Unknown user', '', '', AutorType.SC)
  33. def get_user_by_id(self, author_id: int) -> Author:
  34. for a in self.authors:
  35. if a.id == author_id:
  36. return a
  37. return Author(666, 'Unknown user', '', '', AutorType.SC)