def read_db_config(filename='c:/temp/jquant/config.ini', section='mysql'): """ Read database configuration file and return a dictionary object :param filename: name of the configuration file :param section: section of database configuration :return: a dictionary of database parameters """ if not FileUtil.file_exist(filename): print("configuration file {} does not exit.".format(filter())) return # create parser and read ini configuration file parser = ConfigParser() parser.read(filename) # get section, default to mysql db = {} if parser.has_section(section): items = parser.items(section) for item in items: db[item[0]] = item[1] # {'host': 'localhost', 'database': 'quant', 'user': '******', 'password': '******'} else: raise Exception('{0} not found in the {1} file'.format( section, filename)) return db
def read_price_file(): # SystemEnv.read_config('config.ini') # print(SystemEnv.g_price_file) for key, value in SystemEnv.g_price_file.items(): print('{}={}'.format(key, value)) price_file = os.path.join(SystemEnv.g_price_file['sourcefolder'], "Yahoo_TSLA.csv") if not FileUtil.file_exist(price_file): print("Price File {} does not exist.".format(price_file)) return df_price = pd.read_csv(price_file) return df_price
def read_config(filename='config.ini'): """ Read database configuration file and return a dictionary object :param filename: name of the configuration file :param section: section of database configuration :return: a dictionary of database parameters """ global g_mysql_connection global g_price_file global g_tick_list def configSectionMap(p_section): dict1 = {} options = parser.options(p_section) for option in options: try: dict1[option] = parser.get(p_section, option) if dict1[option] == -1: print("skip: %s" % option) except Exception as ex: print("exception on %s!" % option) dict1[option] = None return dict1 if not FileUtil.file_exist(filename): print("configuration file {} does not exit.".format(filename)) return # create parser and read ini configuration file parser = ConfigParser() parser.read(filename) sections = parser.sections() for section in parser.sections(): if section == ConfigSection.E_MYSQL.value: g_mysql_connection = configSectionMap(section) elif section == ConfigSection.E_PRICE_FILE.value: g_price_file = configSectionMap(section) elif section == ConfigSection.E_TICKER.value: g_tick_list = _listfstr(configSectionMap(section))