import os
import json


def load_config(config_path):
    """

    :param config_path: config folder path
    :return:
    """
    if os.path.exists(os.path.join(config_path, 'config_local.txt')):
        config_path = os.path.join(config_path, 'config_local.txt')
    else:
        config_path = os.path.join(config_path, 'config.txt')
    with open(config_path, 'r', encoding='utf-8') as config_file:
        config_json = json.loads(config_file.read())
    config_json['database'] = 'Telegram_Message'
    return config_json


def size_of_file(file_size):
    units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
    i = 0
    while file_size > 1024.0 and i < len(units) - 1:
        file_size /= 1024.0
        i += 1
    return f'{round(file_size, 2)} {units[i]}'
