# Path: fooltrader/api/technical.py
# def get_security_list(security_type='stock', exchanges=None, start_code=None, end_code=None,
#                       mode='simple', start_list_date=None, codes=None):
#     """
#     get security list.
# 
#     Parameters
#     ----------
#     security_type : str
#         {‘stock’, 'future'},default: stock
#     exchanges : str or list
#         ['sh', 'sz','nasdaq','nyse','amex','shfe','dce','zce'],default: ['sh','sz']
#     start_code : str
#         the start code,work with end,default:None
#         if using codes,it would be ignored
#     end_code : str
#         the end code,works with start,default:None
#         if using codes,it would be ignored
#     mode : str
#         whether parse more security info,{'simple','es'},default:'simple'
#     start_list_date : Timestamp str or Timestamp
#         the filter for start list date,default:None
#     codes : list
#         the exact codes to query,default:None
# 
#     Returns
#     -------
#     DataFrame
#         the security list
# 
#     """
#     df = pd.DataFrame()
#     if type(exchanges) == str:
#         exchanges = [exchanges]
# 
#     if not exchanges:
#         exchanges = SECURITY_TYPE_MAP_EXCHANGES[security_type]
# 
#     if security_type == 'index':
#         df = df.append(pd.DataFrame(CHINA_STOCK_SH_INDEX), ignore_index=True)
#         df = df.append(pd.DataFrame(CHINA_STOCK_SZ_INDEX), ignore_index=True)
#         df = df.append(pd.DataFrame(USA_STOCK_NASDAQ_INDEX), ignore_index=True)
#     else:
#         for exchange in exchanges:
#             the_path = get_security_list_path(security_type, exchange)
#             if os.path.exists(the_path):
#                 converters = None
# 
#                 if mode == 'es' and security_type == 'stock':
#                     converters = {'code': str,
#                                   'sinaIndustry': convert_to_list_if_need,
#                                   'sinaConcept': convert_to_list_if_need,
#                                   'sinaArea': convert_to_list_if_need}
#                 if converters:
#                     df = df.append(pd.read_csv(the_path, converters=converters), ignore_index=True)
#                 else:
#                     df = df.append(pd.read_csv(the_path, dtype=str), ignore_index=True)
# 
#     if not df.empty > 0:
#         df = df_for_date_range(df, start_date=start_list_date)
# 
#         df = df.set_index(df['code'], drop=False)
#         df = df.sort_index()
# 
#         if codes:
#             df = df[df["code"].isin(codes)]
#         elif start_code and end_code:
#             df = df[(df["code"] >= start_code) & (df["code"] <= end_code)]
# 
#         if security_type != 'cryptocurrency':
#             df = df.drop_duplicates(subset='code', keep='last')
# 
#     return df
# 
# Path: fooltrader/contract/files_contract.py
# def get_balance_sheet_path(item):
#     return os.path.join(get_finance_dir(item), "balance_sheet.xls")
# 
# def get_income_statement_path(item):
#     return os.path.join(get_finance_dir(item), "income_statement.xls")
# 
# def get_cash_flow_statement_path(item):
#     return os.path.join(get_finance_dir(item), "cash_flow_statement.xls")


import scrapy
from scrapy import Request
from scrapy import signals
from fooltrader.api.technical import get_security_list
from fooltrader.consts import DEFAULT_BALANCE_SHEET_HEADER
from fooltrader.contract.files_contract import get_balance_sheet_path, get_income_statement_path, \
    get_cash_flow_statement_path
        'DOWNLOAD_DELAY': 2,
        'CONCURRENT_REQUESTS_PER_DOMAIN': 8,

        'SPIDER_MIDDLEWARES': {
            'fooltrader.middlewares.FoolErrorMiddleware': 1000,
        }
    }

    def start_requests(self):
        security_item = self.settings.get("security_item")
        finance_type = self.settings.get("report_type")
        if security_item is not None:
            for request in self.yield_request(security_item, finance_type):
                yield request
        else:
            for _, item in get_security_list().iterrows():
                for request in self.yield_request(item):
                    yield request

    def yield_request(self, item=None, finance_type=None):
        if finance_type == 'balance_sheet':
            url_and_path = [(self.get_balance_sheet_url(item['code']), get_balance_sheet_path(item))]
        elif finance_type == 'income_statement':
            url_and_path = [(self.get_income_statement_url(item['code']), get_income_statement_path(item))]
        elif finance_type == 'cash_flow':
            url_and_path = [(self.get_cash_flow_statement_url(item['code']), get_cash_flow_statement_path(item))]
        else:
            url_and_path = [
                (self.get_balance_sheet_url(item['code']), get_balance_sheet_path(item)),
                (self.get_income_statement_url(item['code']), get_income_statement_path(item)),

# Path: fooltrader/api/technical.py
# def get_security_list(security_type='stock', exchanges=None, start_code=None, end_code=None,
#                       mode='simple', start_list_date=None, codes=None):
#     """
#     get security list.
# 
#     Parameters
#     ----------
#     security_type : str
#         {‘stock’, 'future'},default: stock
#     exchanges : str or list
#         ['sh', 'sz','nasdaq','nyse','amex','shfe','dce','zce'],default: ['sh','sz']
#     start_code : str
#         the start code,work with end,default:None
#         if using codes,it would be ignored
#     end_code : str
#         the end code,works with start,default:None
#         if using codes,it would be ignored
#     mode : str
#         whether parse more security info,{'simple','es'},default:'simple'
#     start_list_date : Timestamp str or Timestamp
#         the filter for start list date,default:None
#     codes : list
#         the exact codes to query,default:None
# 
#     Returns
#     -------
#     DataFrame
#         the security list
# 
#     """
#     df = pd.DataFrame()
#     if type(exchanges) == str:
#         exchanges = [exchanges]
# 
#     if not exchanges:
#         exchanges = SECURITY_TYPE_MAP_EXCHANGES[security_type]
# 
#     if security_type == 'index':
#         df = df.append(pd.DataFrame(CHINA_STOCK_SH_INDEX), ignore_index=True)
#         df = df.append(pd.DataFrame(CHINA_STOCK_SZ_INDEX), ignore_index=True)
#         df = df.append(pd.DataFrame(USA_STOCK_NASDAQ_INDEX), ignore_index=True)
#     else:
#         for exchange in exchanges:
#             the_path = get_security_list_path(security_type, exchange)
#             if os.path.exists(the_path):
#                 converters = None
# 
#                 if mode == 'es' and security_type == 'stock':
#                     converters = {'code': str,
#                                   'sinaIndustry': convert_to_list_if_need,
#                                   'sinaConcept': convert_to_list_if_need,
#                                   'sinaArea': convert_to_list_if_need}
#                 if converters:
#                     df = df.append(pd.read_csv(the_path, converters=converters), ignore_index=True)
#                 else:
#                     df = df.append(pd.read_csv(the_path, dtype=str), ignore_index=True)
# 
#     if not df.empty > 0:
#         df = df_for_date_range(df, start_date=start_list_date)
# 
#         df = df.set_index(df['code'], drop=False)
#         df = df.sort_index()
# 
#         if codes:
#             df = df[df["code"].isin(codes)]
#         elif start_code and end_code:
#             df = df[(df["code"] >= start_code) & (df["code"] <= end_code)]
# 
#         if security_type != 'cryptocurrency':
#             df = df.drop_duplicates(subset='code', keep='last')
# 
#     return df
# 
# Path: fooltrader/contract/files_contract.py
# def get_balance_sheet_path(item):
#     return os.path.join(get_finance_dir(item), "balance_sheet.xls")
# 
# def get_income_statement_path(item):
#     return os.path.join(get_finance_dir(item), "income_statement.xls")
# 
# def get_cash_flow_statement_path(item):
#     return os.path.join(get_finance_dir(item), "cash_flow_statement.xls")


# Path: fooltrader/spiders/chinastock/stock_finance_spider.py
import scrapy
from scrapy import Request
from scrapy import signals
from fooltrader.api.technical import get_security_list
from fooltrader.consts import DEFAULT_BALANCE_SHEET_HEADER
from fooltrader.contract.files_contract import get_balance_sheet_path, get_income_statement_path, \
    get_cash_flow_statement_path

        'DOWNLOAD_DELAY': 2,
        'CONCURRENT_REQUESTS_PER_DOMAIN': 8,

        'SPIDER_MIDDLEWARES': {
            'fooltrader.middlewares.FoolErrorMiddleware': 1000,
        }
    }

    def start_requests(self):
        security_item = self.settings.get("security_item")
        finance_type = self.settings.get("report_type")
        if security_item is not None:
            for request in self.yield_request(security_item, finance_type):
                yield request
        else:
            for _, item in get_security_list().iterrows():
                for request in self.yield_request(item):
                    yield request

    def yield_request(self, item=None, finance_type=None):
        if finance_type == 'balance_sheet':
            url_and_path = [(self.get_balance_sheet_url(item['code']), get_balance_sheet_path(item))]
        elif finance_type == 'income_statement':
            url_and_path = [(self.get_income_statement_url(item['code']), get_income_statement_path(item))]
        elif finance_type == 'cash_flow':
            url_and_path = [(self.get_cash_flow_statement_url(item['code']), get_cash_flow_statement_path(item))]
        else:
            url_and_path = [
                (self.get_balance_sheet_url(item['code']), get_balance_sheet_path(item)),
                (self.get_income_statement_url(item['code']), get_income_statement_path(item)),

                (self.get_cash_flow_statement_url(item['code']), get_cash_flow_statement_path(item))]