This commit is contained in:
2025-09-10 13:26:53 +08:00
parent 20e3a294ea
commit a19db36b7d
14 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
# 读取 Dict 目录下 ChinaCitys2025.json
import json
with open(r'/Dict/ChinaCitys2025.json', 'r', encoding='utf-8') as f:
data = json.load(f)
# 筛选云南省数据并格式化输出
try:
# 查找名称为"云南省"的条目
yunnan_data = next(item for item in data if item.get('name') == '云南省')
# 仅保留到县区级,移除街道数据
for city in yunnan_data.get('citys', []):
for area in city.get('areas', []):
# 删除乡镇/街道层级数据
area.pop('towns', None)
# 格式化输出
print(json.dumps(yunnan_data, ensure_ascii=False, indent=4))
with open('../../Dict/云南省行政区划数据.json', 'w', encoding='utf-8') as outfile:
json.dump(yunnan_data, outfile, ensure_ascii=False, indent=4)
print("\n数据已保存至:云南省行政区划数据.json")
except StopIteration:
print("错误:未找到云南省相关记录")
except Exception as e:
print(f"处理数据时发生错误:{str(e)}")

View File

@@ -0,0 +1,60 @@
# 读取 Doc目录 数据库-2015-2024-v2.xlsx 文件内容
# pip install openpyxl
import openpyxl
from Config.Config import EXCEL_PATH
from Util.AreaUtil import query_area_info
file_name = EXCEL_PATH
# 初始化统计变量
success_count = 0
error_count = 0
error_details = []
# 读取Excel文件并获取所有sheet名称
try:
# 加载工作簿
workbook = openpyxl.load_workbook(file_name, read_only=True)
sheet_names = workbook.sheetnames
if sheet_names:
first_sheet = workbook[sheet_names[0]]
# 读取所有行数据
rows = list(first_sheet.iter_rows(values_only=True))
total_count = len(rows[2:]) # 排除表头的总数据行数
# 跳过前两行表头,从第三行开始处理数据
for row_num, row in enumerate(rows[2:], start=3):
# 假设行政区划名称在第一列索引0
if row and row[0]:
area_name = row[0]
result = query_area_info(area_name)
if result:
success_count += 1
print(f"✅ 行 {row_num}: {area_name} -> 全称: {result['full_name']}, 行政区划码: {result['area_code']}")
else:
error_count += 1
error_details.append(f"{row_num}: '{area_name}'")
print(f"❌ 行 {row_num}: 未找到 '{area_name}' 的相关信息")
# 输出汇总结果
print("\n==================== 匹配结果汇总 ====================")
print(f"📊 总记录数: {total_count}, 成功匹配: {success_count}, 匹配失败: {error_count}")
print(f"📈 匹配成功率: {success_count/total_count*100:.2f}%\n")
if error_details:
print("❌ 匹配失败详情:")
for detail in error_details:
print(f" - {detail}")
else:
print("✅ 所有记录均成功匹配!")
workbook.close()
except FileNotFoundError:
print(f"🔴 错误:找不到文件 '{file_name}'")
except Exception as e:
print(f"🔴 读取Excel时发生错误{str(e)}")

View File

@@ -0,0 +1,32 @@
import openpyxl
from Config.Config import EXCEL_PATH
file_name = EXCEL_PATH
sheetNameArray = ['人口', '毛入学率', '学校数', '班级数', '招生数', '在校生数', '教职工数、专任教师数',
'学校面积、教学辅助房面积']
# 初始化检查状态变量
missing_sheets = []
try:
# 加载工作簿
workbook = openpyxl.load_workbook(file_name, read_only=True)
sheet_names = workbook.sheetnames
workbook.close()
# 检查指定Sheet是否存在
missing_sheets = [sheet for sheet in sheetNameArray if sheet not in sheet_names]
# 输出检查结果
if not missing_sheets:
print("✅ 所有指定Sheet均存在")
else:
print(f"❌ 检查失败:发现{len(missing_sheets)}个缺失Sheet")
print("🔍 缺失列表:")
for sheet in missing_sheets:
print(f" - {sheet}")
except FileNotFoundError:
print(f"🔴 错误Excel文件 '{file_name}' 不存在")
except Exception as e:
print(f"🔴 处理Excel时发生错误{str(e)}")

0
Tools/Check/__init__.py Normal file
View File