Beispiel #1
0
    def __replicate_old_nav_files(self):
        """
            对于当日数据文件缺失情况,如果需要的文件在邮件中没有找到,
            则复制前一日的数据文件作为代替,这样实现最简单,后续的解析
            文件程序直接把前一日数据当作当日数据解析,但必须保证前一日
            数据文件存在。
        :return:
        """
        rep_date = Calendar.instance().get_prev_trading_day(
            ref_date=self.dt_date)  # 再向前一个交易日 T-2
        # 遍历文件映射
        for i, (expt_file, v) in self.nav_map.items():
            if not v:  # 未找到的文件
                old_file = __make_file_name(ref_date, self.date_ptn[i],
                                            self.data_files[i])
                old_path = os.path.join(self.nav_save_path, old_file)
                new_path = os.path.join(self.nav_save_path, expt_file)
                shutils.copy(old_path, new_path)

        def __make_file_name(ref_date, date_ptn, file_name):
            if date_ptn == 'yyyymmdd':
                ret_name = ''.join(
                    [file_name, ref_date.strftime('%Y%m%d'), '.xls'])
            elif date_ptn == 'yyyy-mm-dd':
                ret_name = ''.join(
                    [file_name,
                     ref_date.strftime('%Y-%m-%d'), '.xls'])
            else:
                ret_name = ''
            return ret_name
Beispiel #2
0
 def set_conf_params(self, mod_config):
     self.dt_date = Calendar.instance().get_prev_trading_day()
     self.src_smtp = mod_config.src_smtp
     self.smtp_user = mod_config.src_user
     self.smtp_pass = mod_config.src_password
     self.des_accounts = mod_config.des_accounts
     self.msg_accounts = mod_config.msg_accounts
     self.report_file = mod_config.report_file
Beispiel #3
0
 def run(self, conf_file):
     try:
         conf_mod = Config(conf_file)
         conf_mod.load_config()
         conf_info = conf_mod.parse_config()
         Calendar.instance().load_calendar_file(conf_info.calendar.calendar_file)
         if Calendar.instance().is_trading_day():
             self.scanner.set_conf_params(conf_info.scanner)
             self.parser.set_conf_params(conf_info.parser)
             self.filler.set_conf_params(conf_info.filler)
             self.sender.set_conf_params(conf_info.sender)
             #
             self.scanner.scan_nav_files()
             nav_dict = self.parser.parse_nav_files()
             self.filler.fill_report_files(nav_dict)
             self.sender.send_report_mail()
         else:
             pass
     except Exception as e:
         err_msg = '程序运行出现异常,相关信息:{e_info}。请检查报告程序'.format(e_info=e)
         self.sender.send_error_message(err_msg)
Beispiel #4
0
    def set_conf_params(self, mod_config):
        self.dt_date = Calendar.instance().get_prev_trading_day()
        self.data_files = mod_config.data_files
        self.prod_names = mod_config.prod_names
        self.date_patterns = mod_config.date_patterns
        self.input_path = mod_config.input_path
        self.unit_nav_items = mod_config.unit_nav_items
        self.accum_ret_items = mod_config.accum_ret_items
        self.ttl_nav_items = mod_config.ttl_nav_items

        for i, (f_name, date_ptn) in enumerate(zip(self.data_files, self.date_patterns)):
            # date_pattern 和 data_file 两个 列表必须一一对应,否则会出错
            if date_ptn == 'yyyymmdd':
                self.data_files[i] = ''.join([f_name, self.dt_date.strftime('%Y%m%d'), '.xls'])
            elif date_ptn == 'yyyy-mm-dd':
                self.data_files[i] = ''.join([f_name, self.dt_date.strftime('%Y-%m-%d'), '.xls'])
        self.nav_map = {f_:0 for f_ in self.data_files} # 文件映射
        self.res_dict = {prod_:NavNode() for prod_ in self.prod_names}
Beispiel #5
0
 def set_conf_params(self, mod_config):
     self.dt_date = Calendar.instance().get_prev_trading_day()
     self.pop3_host = mod_config.pop3_host
     self.pop3_user = mod_config.pop3_user
     self.pop3_pass = mod_config.pop3_password
     self.data_files = mod_config.data_files
     self.data_providers = mod_config.data_providers
     self.date_patterns = mod_config.date_patterns
     self.nav_save_path = mod_config.output_path  # Data file path
     for i, (f_name,
             date_ptn) in enumerate(zip(self.data_files,
                                        self.date_patterns)):
         # date_pattern 和 data_file 两个列表必须一一对应,否则会出错
         # 上述实现效率并不高,但方便,如果讲求效率需要优化
         if date_ptn == 'yyyymmdd':
             self.data_files[i] = ''.join(
                 [f_name, self.dt_date.strftime('%Y%m%d'), '.xls'])
         elif date_ptn == 'yyyy-mm-dd':
             self.data_files[i] = ''.join(
                 [f_name, self.dt_date.strftime('%Y-%m-%d'), '.xls'])
     self.nav_map = {f_: 0 for f_ in self.data_files}  # 文件映射
Beispiel #6
0
 def set_conf_params(self, conf_info):
     self.dt_date = Calendar.instance().get_prev_trading_day()
     self.report_file = conf_info.report_file
     self.prod_names = conf_info.prod_names