feat: implemented genre to external file
This commit is contained in:
parent
df1743c695
commit
636645e862
@ -1,3 +1,12 @@
|
|||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, Generator, List, Set, Type, Union
|
||||||
|
|
||||||
|
from ..download import Downloader, Page, components
|
||||||
|
from ..utils.config import main_settings
|
||||||
|
from .utils import ask_for_bool, cli_function
|
||||||
|
|
||||||
|
|
||||||
class GenreIO(components.HumanIO):
|
class GenreIO(components.HumanIO):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ask_to_create(option: components.Option) -> bool:
|
def ask_to_create(option: components.Option) -> bool:
|
||||||
@ -42,4 +51,3 @@ def get_genre() -> str:
|
|||||||
genre = select_genre.choose(input("> "))
|
genre = select_genre.choose(input("> "))
|
||||||
|
|
||||||
return genre.value
|
return genre.value
|
||||||
|
|
@ -49,6 +49,8 @@ class Option(Generic[P]):
|
|||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
super(Option, self).__init__()
|
||||||
|
|
||||||
def _to_option_string(self, value: Any) -> str:
|
def _to_option_string(self, value: Any) -> str:
|
||||||
if hasattr(value, "option_string"):
|
if hasattr(value, "option_string"):
|
||||||
return value.option_string
|
return value.option_string
|
||||||
@ -88,6 +90,9 @@ class Option(Generic[P]):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
|
def __iter__(self) -> Generator[Option[P], None, None]:
|
||||||
|
yield self
|
||||||
|
|
||||||
|
|
||||||
class Select(Generic[P]):
|
class Select(Generic[P]):
|
||||||
OPTION: Type[Option[P]] = Option
|
OPTION: Type[Option[P]] = Option
|
||||||
@ -106,6 +111,8 @@ class Select(Generic[P]):
|
|||||||
self._options: List[Option[P]] = []
|
self._options: List[Option[P]] = []
|
||||||
self.extend(data)
|
self.extend(data)
|
||||||
|
|
||||||
|
super(Select, self).__init__(**kwargs)
|
||||||
|
|
||||||
def append(self, value: P) -> Option[P]:
|
def append(self, value: P) -> Option[P]:
|
||||||
option = self.option(value)
|
option = self.option(value)
|
||||||
self._options.append(option)
|
self._options.append(option)
|
||||||
@ -126,10 +133,11 @@ class Select(Generic[P]):
|
|||||||
def __iter__(self) -> Generator[Option, None, None]:
|
def __iter__(self) -> Generator[Option, None, None]:
|
||||||
_index = 0
|
_index = 0
|
||||||
|
|
||||||
for i, option in enumerate(self._options_to_show):
|
for i, o in enumerate(self._options_to_show):
|
||||||
option.index = _index
|
for option in o:
|
||||||
yield option
|
option.index = _index
|
||||||
_index += 1
|
yield option
|
||||||
|
_index += 1
|
||||||
|
|
||||||
def __contains__(self, key: Any) -> bool:
|
def __contains__(self, key: Any) -> bool:
|
||||||
for option in self._options:
|
for option in self._options:
|
||||||
@ -156,3 +164,18 @@ class Select(Generic[P]):
|
|||||||
|
|
||||||
def pprint(self) -> str:
|
def pprint(self) -> str:
|
||||||
return "\n".join(str(option) for option in self)
|
return "\n".join(str(option) for option in self)
|
||||||
|
|
||||||
|
|
||||||
|
class OptionGroup(Option[P], Select[P]):
|
||||||
|
ALPHABET: str = "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
ATTRIBUTES_FORMATTING: Tuple[str, ...] = ("alphabetic_index", "value")
|
||||||
|
|
||||||
|
TEXT_TEMPLATE: str = f"{BColors.HEADER.value}{{alphabetic_index}}) {{value}}{BColors.ENDC.value}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def alphabetic_index(self) -> str:
|
||||||
|
return self.ALPHABET[self.index % len(self.ALPHABET)]
|
||||||
|
|
||||||
|
def __init__(self, value: P, data: Generator[P, None, None] **kwargs):
|
||||||
|
super(OptionGroup, self).__init__(value=value, data=data, **kwargs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user