|
import os |
|
import yaml |
|
import datetime |
|
from typing import Dict, List |
|
|
|
|
|
def get_current_date() -> str: |
|
"""returns present date. |
|
|
|
Returns: |
|
str: return present date as a string. |
|
""" |
|
current_date = datetime.date.today().strftime("%Y-%m-%d") |
|
return current_date |
|
|
|
|
|
def read_yaml(file_path: str) -> Dict: |
|
"""_summary_ |
|
|
|
Args: |
|
file_path (str): wesites.yaml file path |
|
|
|
Raises: |
|
ValueError: raise error is file_path is empty or if websites.yaml file is missing. |
|
|
|
Returns: |
|
Dict: return List websites to be used for websearch. |
|
""" |
|
websites_yaml = None |
|
if not read_yaml: |
|
raise ValueError("Website yaml config file missing") |
|
return websites_yaml |
|
else: |
|
with open(file_path, 'r') as file: |
|
websites_yaml = yaml.load(file, Loader=yaml.SafeLoader) |
|
return websites_yaml |
|
|
|
|
|
def get_websites() -> List[str]: |
|
"""reads websites.yaml file and return list of webistes |
|
|
|
Returns: |
|
List[str]: List of websites |
|
""" |
|
file_path = os.path.join(os.getcwd(), 'websites.yaml') |
|
websites = read_yaml(file_path) |
|
if not websites: |
|
return [] |
|
return websites['public_websites'] |