# Path: kquant_data/api.py
# def all_instruments(path=None, type=None):
#     """
#     得到合约列表
#     :param type:
#     :return:
#     """
#     if path is None:
#         path = os.path.join(__CONFIG_H5_STK_DIR__, "daily", 'Symbol.csv')
# 
#     df = pd.read_csv(path, dtype={'code': str})
# 
#     return df
# 
# Path: kquant_data/wind_resume/wsd.py
# def resume_download_financial_report_quarter(w, wind_codes, root_path, fields=['stm_issuingdate'], dtype=np.datetime64):
#     """
# 
#     其实发现有更新的部分，然后再增量下载其它字段是最合适不过的了，目前此功能还没有实现
#     :param w:
#     :param wind_codes:
#     :return:
#     """
#     dr = pd.date_range(end=datetime.today().date(), periods=4, freq='Q')
#     new_end_str = dr[-1].strftime('%Y-%m-%d')
# 
#     for field in fields:
#         resume_download_daily_many_to_one_file(w,
#                                                wind_codes,
#                                                field,
#                                                dtype, new_end_str,
#                                                root_path,
#                                                option='unit=1;rptType=1;Period=Q;Days=Alldays')
# 
# Path: kquant_data/config.py
# __CONFIG_H5_STK_DIR__ = r'D:\DATA_STK'
# 
# __CONFIG_H5_STK_FACTOR_DIR__ = os.path.join(__CONFIG_H5_STK_DIR__, 'factor')


import os
import numpy as np
from WindPy import w
from kquant_data.api import all_instruments
from kquant_data.wind_resume.wsd import resume_download_financial_report_quarter
from kquant_data.config import __CONFIG_H5_STK_DIR__, __CONFIG_H5_STK_FACTOR_DIR__
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
下载财报一类的信息
"""


if __name__ == '__main__':
    w.start()

    path = os.path.join(__CONFIG_H5_STK_DIR__, '1day', 'Symbol.csv')
    Symbols = all_instruments(path)
    wind_codes = list(Symbols['wind_code'])

    # 下载时间类型的数据
    fields = ['stm_issuingdate']
    if True:
        resume_download_financial_report_quarter(w, wind_codes, __CONFIG_H5_STK_FACTOR_DIR__, fields=fields,
                                                 dtype=np.datetime64)

    # 下载一般类型的数据，只在季报中出现，平时不出现的数据，如roe，pb_lf由于每天变化不通过这种方式下载
    fields = ['close', 'cap_stk', 'np_belongto_parcomsh', 'eqy_belongto_parcomsh']
    fields = ['ebit', 'ebit2', 'networkingcapital', 'fix_assets', 'ev', 'mkt_cap_ard', 'interestdebt']
    fields = ['wgsd_net_inc', 'oper_rev', 'wgsd_oper_cf', 'wgsd_liabs_lt', 'monetary_cap', 'tot_assets']
    fields = ['np_belongto_parcomsh', 'eqy_belongto_parcomsh']
    fields = ['close']
    fields = ['np_belongto_parcomsh']
    fields = ['pb_lf']
    fields = ['roe']
    if False:

# Path: kquant_data/api.py
# def all_instruments(path=None, type=None):
#     """
#     得到合约列表
#     :param type:
#     :return:
#     """
#     if path is None:
#         path = os.path.join(__CONFIG_H5_STK_DIR__, "daily", 'Symbol.csv')
# 
#     df = pd.read_csv(path, dtype={'code': str})
# 
#     return df
# 
# Path: kquant_data/wind_resume/wsd.py
# def resume_download_financial_report_quarter(w, wind_codes, root_path, fields=['stm_issuingdate'], dtype=np.datetime64):
#     """
# 
#     其实发现有更新的部分，然后再增量下载其它字段是最合适不过的了，目前此功能还没有实现
#     :param w:
#     :param wind_codes:
#     :return:
#     """
#     dr = pd.date_range(end=datetime.today().date(), periods=4, freq='Q')
#     new_end_str = dr[-1].strftime('%Y-%m-%d')
# 
#     for field in fields:
#         resume_download_daily_many_to_one_file(w,
#                                                wind_codes,
#                                                field,
#                                                dtype, new_end_str,
#                                                root_path,
#                                                option='unit=1;rptType=1;Period=Q;Days=Alldays')
# 
# Path: kquant_data/config.py
# __CONFIG_H5_STK_DIR__ = r'D:\DATA_STK'
# 
# __CONFIG_H5_STK_FACTOR_DIR__ = os.path.join(__CONFIG_H5_STK_DIR__, 'factor')


# Path: demo_stock/A_1day/D03_download_report.py
import os
import numpy as np
from WindPy import w
from kquant_data.api import all_instruments
from kquant_data.wind_resume.wsd import resume_download_financial_report_quarter
from kquant_data.config import __CONFIG_H5_STK_DIR__, __CONFIG_H5_STK_FACTOR_DIR__

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
下载财报一类的信息
"""


if __name__ == '__main__':
    w.start()

    path = os.path.join(__CONFIG_H5_STK_DIR__, '1day', 'Symbol.csv')
    Symbols = all_instruments(path)
    wind_codes = list(Symbols['wind_code'])

    # 下载时间类型的数据
    fields = ['stm_issuingdate']
    if True:
        resume_download_financial_report_quarter(w, wind_codes, __CONFIG_H5_STK_FACTOR_DIR__, fields=fields,
                                                 dtype=np.datetime64)

    # 下载一般类型的数据，只在季报中出现，平时不出现的数据，如roe，pb_lf由于每天变化不通过这种方式下载
    fields = ['close', 'cap_stk', 'np_belongto_parcomsh', 'eqy_belongto_parcomsh']
    fields = ['ebit', 'ebit2', 'networkingcapital', 'fix_assets', 'ev', 'mkt_cap_ard', 'interestdebt']
    fields = ['wgsd_net_inc', 'oper_rev', 'wgsd_oper_cf', 'wgsd_liabs_lt', 'monetary_cap', 'tot_assets']
    fields = ['np_belongto_parcomsh', 'eqy_belongto_parcomsh']
    fields = ['close']
    fields = ['np_belongto_parcomsh']
    fields = ['pb_lf']
    fields = ['roe']
    if False:

        resume_download_financial_report_quarter(w, wind_codes, __CONFIG_H5_STK_FACTOR_DIR__, fields=fields, dtype=None)