diff --git a/fishbase/db/fish_data.sqlite b/fishbase/db/fish_data.sqlite index 6db33ad..38b146a 100644 Binary files a/fishbase/db/fish_data.sqlite and b/fishbase/db/fish_data.sqlite differ diff --git a/fishbase/fish_data.py b/fishbase/fish_data.py index 438f4b1..d463d43 100644 --- a/fishbase/fish_data.py +++ b/fishbase/fish_data.py @@ -9,7 +9,8 @@ """ -# 2018.12.9 v1.1.3 created +# 2018.12.9 v1.1.3 created by David Yi +# 2019.1.13 edit by David Yi, #202 优化 class CardBin(), class IdCard() import re import sqlite3 @@ -162,7 +163,7 @@ def check_number(cls, id_number): # --- # 2018.12.14 12.16 create by David Yi, add in v1.1.4, github issue #139 @classmethod - def get_zonecode_by_area(cls, area_str, match_type='EXACT', result_type='LIST'): + def get_zone_info(cls, area_str, match_type='EXACT', result_type='LIST'): """ 输入包含省份、城市、地区信息的内容,返回地区编号; @@ -226,10 +227,10 @@ def get_zonecode_by_area(cls, area_str, match_type='EXACT', result_type='LIST'): if match_type == 'EXACT': values = sqlite_query('fish_data.sqlite', - 'select zone, note from cn_idcard where note = :area', {"area": area_str}) + 'select zone, areanote from cn_idcard where areanote = :area', {"area": area_str}) if match_type == 'FUZZY': values = sqlite_query('fish_data.sqlite', - 'select zone, note from cn_idcard where note like :area', + 'select zone, areanote from cn_idcard where areanote like :area', {"area": '%' + area_str + '%'}) # result_type 结果数量判断处理 @@ -250,7 +251,7 @@ def get_zonecode_by_area(cls, area_str, match_type='EXACT', result_type='LIST'): # 2019.01.07 create by Hu Jun, add in v1.1.6, github issue #192 @classmethod - def get_note_by_province(cls, province_code): + def get_areanote_info(cls, province): """ 输入省份代码,返回地区信息; @@ -287,8 +288,8 @@ def get_note_by_province(cls, province_code): """ values = sqlite_query('fish_data.sqlite', - 'select zone, note from cn_idcard where province = :province_code ', - {"province_code": province_code}) + 'select zone, areanote from cn_idcard where province = :province_code ', + {"province_code": province}) return values # 2019.01.07 create by Hu Jun, add in v1.1.6, github issue #192 @@ -325,7 +326,7 @@ def get_cn_idcard(cls): """ values = sqlite_query('fish_data.sqlite', - 'select province, city, zone, note from cn_idcard', + 'select province, city, zone, areanote from cn_idcard', {}) return values @@ -428,7 +429,7 @@ def check_bankcard(cls, card_number_str): # 2018.12.18 create by David Yi, add in v1.1.4, github issue #159 # 2019.1.5 edit, v1.1.6 github issue #188, 修改函数名称 @classmethod - def get_bank_by_name(cls, bankname): + def get_bank_info(cls, bankname): """ 银行名称,返回银行代码; @@ -455,7 +456,7 @@ def get_bank_by_name(cls, bankname): """ values = sqlite_query('fish_data.sqlite', - 'select bank,bankname from cn_bankname where bankname=:bankname', + 'select bankcode,bankname from cn_bank where bankname=:bankname', {"bankname": bankname}) return values @@ -465,7 +466,7 @@ def get_bank_by_name(cls, bankname): # 2018.12.17 create by David Yi, add in v1.1.4, github issue #149 # 2019.1.5 edit, v1.1.6 github issue #188, 修改函数名称 @classmethod - def get_cardbin_bank(cls, bank, card_type): + def get_cardbin_info(cls, bank, card_type): """ 输入银行、借记贷记卡种类,返回有效的卡 bin; @@ -495,8 +496,8 @@ def get_cardbin_bank(cls, bank, card_type): """ values = sqlite_query('fish_data.sqlite', - 'select bin,bank,card_type,length from cn_cardbin where bank=:bank ' - 'and card_type=:card_type', + 'select bin,bankcode,cardtype,length from cn_cardbin where bankcode=:bank ' + 'and cardtype=:card_type', {"bank": bank, "card_type": card_type}) return values diff --git a/fishbase/fish_random.py b/fishbase/fish_random.py index 937e3c5..d73e2f1 100644 --- a/fishbase/fish_random.py +++ b/fishbase/fish_random.py @@ -6,6 +6,7 @@ """ # 2019.1.6 edit by David Yi, #187 #188 修改 IdCard 和 CardBin 两个类,对这里有修改 +# 2019.1.13 edit by David Yi, #202 优化 class CardBin(), class IdCard() # 2018.12.26 v1.1.5 created import random @@ -227,7 +228,7 @@ def get_random_zone_name(province_zone): """ # 获取省份下的地区信息 province_num = str(province_zone)[:2] - values = IdCard.get_note_by_province(province_num) + values = IdCard.get_areanote_info(province_num) # 选出省份名称 province_name_item = [item for item in values if item[0] == str(province_zone)] @@ -269,7 +270,7 @@ def gen_address(province): """ # 获取省份下的地区信息 province_num = str(province)[:2] - note = IdCard.get_note_by_province(province_num) + note = IdCard.get_areanote_info(province_num) if not note: raise ValueError('province_zone error, please check and try again') # 第一项是省份名称 @@ -370,7 +371,7 @@ def gen_bank_card(bank_name, card_type): --- """ - bank = CardBin.get_bank_by_name(bank_name) + bank = CardBin.get_bank_info(bank_name) if not bank: raise ValueError('bank_name {} error, check and try again'.format(bank_name)) @@ -378,7 +379,7 @@ def gen_bank_card(bank_name, card_type): bank_code = bank[0][0] # 获取 cardbin - all_card_bin = CardBin.get_cardbin_bank(bank_code, card_type) + all_card_bin = CardBin.get_cardbin_info(bank_code, card_type) random_cardbin_info = random.choice(all_card_bin) card_bin = random_cardbin_info[0] diff --git a/test/test_data.py b/test/test_data.py index 1522619..f43832b 100644 --- a/test/test_data.py +++ b/test/test_data.py @@ -42,20 +42,20 @@ def test_is_valid_id_number(self): def test_get_zonecode_by_area(self): # area_str,基本测试 values = [('110000', '北京市')] - assert IdCard.get_zonecode_by_area('北京市') == values + assert IdCard.get_zone_info('北京市') == values # area_str,显示设定参数 - result = IdCard.get_zonecode_by_area(area_str='上海市') + result = IdCard.get_zone_info(area_str='上海市') values = [('310000', '上海市')] assert result == values # area_str, match_type = EXACT 精确 - result = IdCard.get_zonecode_by_area(area_str='北京市', match_type='EXACT') + result = IdCard.get_zone_info(area_str='北京市', match_type='EXACT') values = [('110000', '北京市')] assert result == values # area_str, match_type = FUZZY 模糊 - result = IdCard.get_zonecode_by_area(area_str='北京市', match_type='FUZZY') + result = IdCard.get_zone_info(area_str='北京市', match_type='FUZZY') values = [('110000', '北京市'), ('110100', '北京市市辖区'), ('110101', '北京市东城区'), ('110102', '北京市西城区'), ('110103', '北京市崇文区'), ('110104', '北京市宣武区'), ('110105', '北京市朝阳区'), ('110106', '北京市丰台区'), ('110107', '北京市石景山区'), ('110108', '北京市海淀区'), ('110109', '北京市门头沟区'), ('110111', '北京市房山区'), @@ -64,7 +64,7 @@ def test_get_zonecode_by_area(self): assert result == values # area_str, match_type 模糊, result_type=LIST 列表 - result = IdCard.get_zonecode_by_area(area_str='西安市', match_type='FUZZY', result_type='LIST') + result = IdCard.get_zone_info(area_str='西安市', match_type='FUZZY', result_type='LIST') values = [('610100', '陕西省西安市'), ('610101', '陕西省西安市市辖区'), ('610102', '陕西省西安市新城区'), ('610103', '陕西省西安市碑林区'), ('610104', '陕西省西安市莲湖区'), ('610111', '陕西省西安市灞桥区'), ('610112', '陕西省西安市未央区'), ('610113', '陕西省西安市雁塔区'), ('610114', '陕西省西安市阎良区'), @@ -72,21 +72,21 @@ def test_get_zonecode_by_area(self): assert result == values # area_str, match_type 精确, result_type=LIST 列表 - result = IdCard.get_zonecode_by_area(area_str='北京市', match_type='EXACT', result_type='LIST') + result = IdCard.get_zone_info(area_str='北京市', match_type='EXACT', result_type='LIST') values = [('110000', '北京市')] assert result == values # area_str, match_type 精确, result_type=SINGLE_STR 字符串 - result = IdCard.get_zonecode_by_area(area_str='北京市', match_type='EXACT', result_type='SINGLE_STR') + result = IdCard.get_zone_info(area_str='北京市', match_type='EXACT', result_type='SINGLE_STR') values = '110000' assert result == values # area_str, 结果大于20个,返回20个 - result = len(IdCard.get_zonecode_by_area(area_str='市', match_type='FUZZY')) + result = len(IdCard.get_zone_info(area_str='市', match_type='FUZZY')) assert result == 20 # area_str, match_type 精确, result_type=SINGLE_STR 字符串, 无结果返回 - result = IdCard.get_zonecode_by_area(area_str='美国', match_type='EXACT', result_type='SINGLE_STR') + result = IdCard.get_zone_info(area_str='美国', match_type='EXACT', result_type='SINGLE_STR') values = '' assert result == values @@ -94,7 +94,7 @@ def test_get_zonecode_by_area(self): def test_cardbin_get_cardbin_bank(self): # 基本测试,检查返回的结果集的第一个结果 values = ('370247', 'ICBC', 'CC', 15) - result = CardBin.get_cardbin_bank('ICBC', 'CC')[0] + result = CardBin.get_cardbin_info('ICBC', 'CC')[0] assert result == values # 测试完整的返回 list @@ -103,7 +103,7 @@ def test_cardbin_get_cardbin_bank(self): ('518718', 'CMB', 'CC', 16), ('622575', 'CMB', 'CC', 16), ('622576', 'CMB', 'CC', 16), ('622577', 'CMB', 'CC', 16), ('622578', 'CMB', 'CC', 16), ('622579', 'CMB', 'CC', 16), ('622581', 'CMB', 'CC', 16), ('622582', 'CMB', 'CC', 16)] - result = CardBin.get_cardbin_bank('CMB', 'CC') + result = CardBin.get_cardbin_info('CMB', 'CC') assert result == values # 2018.12.18 edit by David Yi @@ -131,22 +131,22 @@ def test_cardbin_check_bankcard(self): def test_cardbin_get_bank_by_name(self): # 测试银行卡名称查询 values = [('CMB', '招商银行')] - result = CardBin.get_bank_by_name('招商银行') + result = CardBin.get_bank_info('招商银行') assert result == values # 测试银行卡名称查询 values = 'HSB' - result = CardBin.get_bank_by_name('恒生银行') + result = CardBin.get_bank_info('恒生银行') assert result[0][0] == values # 测试不存在银行卡名称 values = [] - result = CardBin.get_bank_by_name('招银行') + result = CardBin.get_bank_info('招银行') assert result == values # 2019.01.07 edit by Hu Jun def test_get_note_by_province(self): - values = IdCard.get_note_by_province('11') + values = IdCard.get_areanote_info('11') assert values[0][0].startswith('11') # 2019.01.07 edit by Hu Jun