olivia_finder.data_source.data_source
1from __future__ import annotations 2from abc import ABC, abstractmethod 3from typing import List 4from ..utilities.config import Configuration 5from ..utilities.logger import MyLogger 6 7class DataSource(ABC): 8 ''' 9 Base class for data sources. 10 11 .. warning:: 12 13 This class is an abstract class, so it can't be instantiated. 14 15 The subclasses must implement the methods: 16 - `DataSource.obtain_package_names` 17 - `DataSource.obtain_package_data` 18 - `DataSource.obtain_packages_data` 19 20 21 .. note:: 22 23 The `name` and `description` parameters are mandatory, and must be passed as arguments. 24 The use of this parameters is to be able to identify the data source, and to be able to show a description of it. 25 ''' 26 27 def __init__(self): 28 ''' 29 Initialize the class 30 ''' 31 self.logger = MyLogger().get_logger("logger_datasource") 32 33 @abstractmethod 34 def obtain_package_names(self) -> List[str]: 35 """ 36 Obtains the list of packages from the data source. 37 38 Is an optional method, if the data source does not implement it, it will 39 be considered that it does not have a list of packages available. 40 41 Raises 42 ------ 43 NotImplementedError 44 Because this method is not implemented in the base class 45 """ 46 raise NotImplementedError 47 48 @abstractmethod 49 def obtain_package_data(self, package_name:str) -> dict: 50 """ 51 Obtains the data of a package from the data source as a dictionary. 52 53 Parameters 54 ---------- 55 package_name : str 56 The name of the package to obtain the data 57 58 Raises 59 ------ 60 NotImplementedError 61 Because this method is not implemented in the base class 62 """ 63 raise NotImplementedError 64 65 @abstractmethod 66 def obtain_packages_data(self, package_names: List[str]) -> List[dict]: 67 ''' 68 Obtains the data of a list of package names from the data source. 69 70 Raises 71 ------ 72 NotImplementedError 73 Because this method is not implemented in the base class 74 ''' 75 raise NotImplementedError 76 77 78 79
class
DataSource(abc.ABC):
9class DataSource(ABC): 10 ''' 11 Base class for data sources. 12 13 .. warning:: 14 15 This class is an abstract class, so it can't be instantiated. 16 17 The subclasses must implement the methods: 18 - `DataSource.obtain_package_names` 19 - `DataSource.obtain_package_data` 20 - `DataSource.obtain_packages_data` 21 22 23 .. note:: 24 25 The `name` and `description` parameters are mandatory, and must be passed as arguments. 26 The use of this parameters is to be able to identify the data source, and to be able to show a description of it. 27 ''' 28 29 def __init__(self): 30 ''' 31 Initialize the class 32 ''' 33 self.logger = MyLogger().get_logger("logger_datasource") 34 35 @abstractmethod 36 def obtain_package_names(self) -> List[str]: 37 """ 38 Obtains the list of packages from the data source. 39 40 Is an optional method, if the data source does not implement it, it will 41 be considered that it does not have a list of packages available. 42 43 Raises 44 ------ 45 NotImplementedError 46 Because this method is not implemented in the base class 47 """ 48 raise NotImplementedError 49 50 @abstractmethod 51 def obtain_package_data(self, package_name:str) -> dict: 52 """ 53 Obtains the data of a package from the data source as a dictionary. 54 55 Parameters 56 ---------- 57 package_name : str 58 The name of the package to obtain the data 59 60 Raises 61 ------ 62 NotImplementedError 63 Because this method is not implemented in the base class 64 """ 65 raise NotImplementedError 66 67 @abstractmethod 68 def obtain_packages_data(self, package_names: List[str]) -> List[dict]: 69 ''' 70 Obtains the data of a list of package names from the data source. 71 72 Raises 73 ------ 74 NotImplementedError 75 Because this method is not implemented in the base class 76 ''' 77 raise NotImplementedError
Base class for data sources.
This class is an abstract class, so it can't be instantiated.
The subclasses must implement the methods:
The name and description parameters are mandatory, and must be passed as arguments.
The use of this parameters is to be able to identify the data source, and to be able to show a description of it.
DataSource()
29 def __init__(self): 30 ''' 31 Initialize the class 32 ''' 33 self.logger = MyLogger().get_logger("logger_datasource")
Initialize the class
@abstractmethod
def
obtain_package_names(self) -> List[str]:
35 @abstractmethod 36 def obtain_package_names(self) -> List[str]: 37 """ 38 Obtains the list of packages from the data source. 39 40 Is an optional method, if the data source does not implement it, it will 41 be considered that it does not have a list of packages available. 42 43 Raises 44 ------ 45 NotImplementedError 46 Because this method is not implemented in the base class 47 """ 48 raise NotImplementedError
Obtains the list of packages from the data source.
Is an optional method, if the data source does not implement it, it will be considered that it does not have a list of packages available.
Raises
- NotImplementedError: Because this method is not implemented in the base class
@abstractmethod
def
obtain_package_data(self, package_name: str) -> dict:
50 @abstractmethod 51 def obtain_package_data(self, package_name:str) -> dict: 52 """ 53 Obtains the data of a package from the data source as a dictionary. 54 55 Parameters 56 ---------- 57 package_name : str 58 The name of the package to obtain the data 59 60 Raises 61 ------ 62 NotImplementedError 63 Because this method is not implemented in the base class 64 """ 65 raise NotImplementedError
Obtains the data of a package from the data source as a dictionary.
Parameters
- package_name (str): The name of the package to obtain the data
Raises
- NotImplementedError: Because this method is not implemented in the base class
@abstractmethod
def
obtain_packages_data(self, package_names: List[str]) -> List[dict]:
67 @abstractmethod 68 def obtain_packages_data(self, package_names: List[str]) -> List[dict]: 69 ''' 70 Obtains the data of a list of package names from the data source. 71 72 Raises 73 ------ 74 NotImplementedError 75 Because this method is not implemented in the base class 76 ''' 77 raise NotImplementedError
Obtains the data of a list of package names from the data source.
Raises
- NotImplementedError: Because this method is not implemented in the base class