#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import csv

# CSV文件路径
csv_file_path = '/Users/v_sat/Documents/trae_projects/bingqi/data/map_data.csv'

# 读取CSV文件
map_data = []
with open(csv_file_path, 'r', encoding='utf-8-sig') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        province = row['省']
        # 更新图片路径为项目内相对路径
        row['地图图片地址'] = f'pic/map/{province}.jpg'
        map_data.append(row)

# 写入更新后的CSV文件
with open(csv_file_path, 'w', newline='', encoding='utf-8-sig') as csvfile:
    fieldnames = ['省', '地图图片地址']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    
    writer.writeheader()
    for row in map_data:
        writer.writerow(row)

print(f'已更新CSV文件: {csv_file_path}')
