| | |
| | | |
| | | |
| | | # 保存单个代码的行业 |
| | | def __save_code_industry(code, industry_name, zyltgb, zyltgb_unit): |
| | | def __save_code_industry(code, code_name, industry_name, zyltgb, zyltgb_unit): |
| | | mysqldb = mysql_data.Mysqldb() |
| | | result = mysqldb.select_one("select * from ths_industry_codes where _id={}".format(code)) |
| | | if result is None: |
| | | mysqldb.execute( |
| | | "insert into ths_industry_codes(_id,second_industry,zyltgb,zyltgb_unit) values('{}','{}','{}',{})".format( |
| | | code, industry_name, zyltgb, zyltgb_unit, round(time.time() * 1000))) |
| | | "insert into ths_industry_codes(_id,_name, second_industry,zyltgb,zyltgb_unit) values('{}','{}','{}','{}',{})".format( |
| | | code, code_name, industry_name, zyltgb, zyltgb_unit, round(time.time() * 1000))) |
| | | else: |
| | | mysqldb.execute( |
| | | "update ths_industry_codes set second_industry='{}',zyltgb='{}',zyltgb_unit={} where _id='{}'".format( |
| | | industry_name, zyltgb, zyltgb_unit, code)) |
| | | if code_name: |
| | | mysqldb.execute( |
| | | "update ths_industry_codes set _name='{}', second_industry='{}',zyltgb='{}',zyltgb_unit={} where _id='{}'".format( |
| | | code_name, industry_name, zyltgb, zyltgb_unit, code)) |
| | | else: |
| | | mysqldb.execute( |
| | | "update ths_industry_codes set second_industry='{}',zyltgb='{}',zyltgb_unit={} where _id='{}'".format( |
| | | industry_name, zyltgb, zyltgb_unit, code)) |
| | | |
| | | |
| | | # 保存行业代码 |
| | | def save_industry_code(datasList): |
| | | def save_industry_code(datasList, code_names): |
| | | for datas in datasList: |
| | | # 查询这批数据所属行业 |
| | | industry_name = __get_industry(datas) |
| | | _list = [] |
| | | for data in datas: |
| | | # 保存 |
| | | __save_code_industry(data["code"], industry_name, data["zyltgb"], data["zyltgb_unit"]) |
| | | code = data["code"] |
| | | __save_code_industry(code, code_names.get(code), industry_name, data["zyltgb"], data["zyltgb_unit"]) |
| | | |
| | | |
| | | # 根据名称获取代码 |
| | | def get_code_by_name(name): |
| | | mysqldb = mysql_data.Mysqldb() |
| | | result = mysqldb.select_one("select * from ths_industry_codes where _name='{}'".format(name)) |
| | | if result is not None: |
| | | return result[0] |
| | | else: |
| | | return None |
| | | |
| | | |
| | | def get_name_by_code(code): |
| | | mysqldb = mysql_data.Mysqldb() |
| | | result = mysqldb.select_one("select * from ths_industry_codes where _id={}".format(code)) |
| | | if result is not None: |
| | | return result[1] |
| | | else: |
| | | return None |
| | | |
| | | if __name__ == "__main__": |
| | | _code_map, _industry_map = get_code_industry_maps() |
| | | print(_code_map, _industry_map) |