# Path: kquant_data/wind/tdays.py
# def read_tdays(path):
#     try:
#         df = pd.read_csv(path, parse_dates=True)
#     except:
#         return None
# 
#     df['date'] = pd.to_datetime(df['date'])
#     df.index = df['date']
#     return df
# 
# def download_tdays(w, startdate, enddate, option=''):
#     """
#     下载交易日数据
#     :param w:
#     :param startdate:
#     :param enddate:
#     :param option:
#     :return:
#     """
#     w.asDateTime = asDateTime
#     w_tdays_data = w.tdays(startdate, enddate, option)
#     df = pd.DataFrame(w_tdays_data.Data, )
#     df = df.T
#     df.columns = ['date']
#     df['date'] = pd.to_datetime(df['date'])
# 
#     return df
# 
# def write_tdays(path, df):
#     df.to_csv(path, date_format='%Y-%m-%d', encoding='utf-8', index=False)


import pandas as pd
from ..wind.tdays import read_tdays, download_tdays, write_tdays
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""

"""


def resume_download_tdays(w, enddate, path):
    """
    增量下载
    :return:
    """
    df_old = read_tdays(path)
    if df_old is None:
        startdate = '1991-01-01'
    else:
        startdate = df_old.index[-1]
    df_new = download_tdays(w, startdate, enddate, option="")
    df = pd.concat([df_old, df_new])

    # 可能要‘去重’，也可能None不能参与合并

# Path: kquant_data/wind/tdays.py
# def read_tdays(path):
#     try:
#         df = pd.read_csv(path, parse_dates=True)
#     except:
#         return None
# 
#     df['date'] = pd.to_datetime(df['date'])
#     df.index = df['date']
#     return df
# 
# def download_tdays(w, startdate, enddate, option=''):
#     """
#     下载交易日数据
#     :param w:
#     :param startdate:
#     :param enddate:
#     :param option:
#     :return:
#     """
#     w.asDateTime = asDateTime
#     w_tdays_data = w.tdays(startdate, enddate, option)
#     df = pd.DataFrame(w_tdays_data.Data, )
#     df = df.T
#     df.columns = ['date']
#     df['date'] = pd.to_datetime(df['date'])
# 
#     return df
# 
# def write_tdays(path, df):
#     df.to_csv(path, date_format='%Y-%m-%d', encoding='utf-8', index=False)


# Path: kquant_data/wind_resume/tdays.py
import pandas as pd
from ..wind.tdays import read_tdays, download_tdays, write_tdays

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

"""


def resume_download_tdays(w, enddate, path):
    """
    增量下载
    :return:
    """
    df_old = read_tdays(path)
    if df_old is None:
        startdate = '1991-01-01'
    else:
        startdate = df_old.index[-1]
    df_new = download_tdays(w, startdate, enddate, option="")
    df = pd.concat([df_old, df_new])

    # 可能要‘去重’，也可能None不能参与合并

    write_tdays(path, df)