#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
__title__ = '平台配置操作工具类'

@Time    : 2020/9/26 21:51
@Author  : Kenny-PC
@Software: PyCharm

# code is far away from bugs with the god animal protecting
    I love animals. They taste delicious.
              ┏┓      ┏┓
            ┏┛┻━━━┛┻┓
            ┃      ☃      ┃
            ┃  ┳┛  ┗┳  ┃
            ┃      ┻      ┃
            ┗━┓      ┏━┛
                ┃      ┗━━━┓
                ┃  神兽保佑    ┣┓
                ┃ 永无BUG!   ┏┛
                ┗┓┓┏━┳┓┏┛
                  ┃┫┫  ┃┫┫
                  ┗┻┛  ┗┻┛
"""

import os
import time
from util.date_util import *
import pandas as pd


def get_yuewen_account_list():
    """
    description:  阅文账号列表
    return:       [['email', 'appsecert']] ->list
    """
    return get_account_list('阅文', 'yuewen_account_config.csv')


def get_zhangdu_account_list():
    """
    description:  掌读账号列表
    return:       [['uid', 'appsecert', 'channel']] ->list
    """
    return get_account_list('掌读', 'zhangdu_account_config.csv')


def get_huasheng_account_list():
    """
    description:  花生账号列表
    return:       [['apiKey', 'apiSecurity', 'stage']] ->list
    """
    return get_account_list('花生', 'huasheng_account_config.csv')


def get_zhangzhongyun_account_list():
    """
    description:  掌中云账号列表
    return:       [['key', 'secert', 'stage']] ->list
    """
    return get_account_list('掌中云', 'zhangzhongyun_account_config.csv')


def get_youshuge_account_list():
    """
    description:  悠书阁账号列表
    return:       [['host_name', 'channel_id', 'secert_key', 'channel', 'stage']] ->list
    """
    return get_account_list('悠书阁', 'youshuge_account_config.csv')


def get_yangguang_account_list():
    """
    des cription:  阳光账号列表
    return:       [['host_name', 'channel_id', 'secert_key', 'channel', 'stage']] ->list
    """
    return get_account_list('阳光', 'yangguang_account_config.csv')


def get_wending_account_list():
    """
    des cription:  文鼎账号列表
    return:       [['consumerkey', 'secretkey', 'siteid', 'stage', 'account']] ->list
    """
    return get_account_list('文鼎', 'wending_account_config.csv')


def get_qiyue_account_list():
    """
    des cription:  七悦账号列表
    return:       [['stage','token']] ->list
    """
    return get_account_list('七悦', 'qiyue_account_config.csv')


def get_account_list(platform, account_file_name):
    """
    description:  读取账号列表
    return:       [['value1_1', 'value1_3'...]...] ->list
    """

    # 得到当前文件的父目录
    parent_dir_path = os.path.dirname(os.path.abspath('.'))
    # print(parent_dir_path)
    file_path = parent_dir_path + "/tests/conf/account/" + account_file_name
    # print('配置文件:', file_path)

    data = pd.read_csv(file_path, header=None, keep_default_na=False, encoding='utf8',converters={0:str})
    account = []
    for i in data.index:
        account.append(list(data.values[i]))

    account_list = list(account)  # 若想用二维列表的形式读取即删掉此行语句
    print('读取到【{platform}】账号数量【{quantity}】个'.format(platform=platform, quantity=len(account_list)))

    return account_list


def get_youshuge_order_query_time(st_unix, et_unix):
    """
    description:  悠书阁的订单查询是按天查询的,没有按小时查询,且每小时查询的时候要判断结束时间要比开始时间大一天,否则查询不到数据
    return:       2020-10-10,2020-10-11 -> (start_time,end_time)
    """
    start_time = time.strftime("%Y-%m-%d", time.localtime(st_unix))
    end_time = time.strftime("%Y-%m-%d", time.localtime(et_unix))
    if start_time == end_time:
        # 如果是同一天,则结束时间加一天
        end_time = time.strftime("%Y-%m-%d", time.localtime(et_unix + 86400))
    return start_time, end_time