0.0.9
This commit is contained in:
@@ -59,28 +59,34 @@ class Api:
|
||||
return None
|
||||
return response
|
||||
|
||||
# def main():
|
||||
# """
|
||||
# 从同目录的 `bakeries.csv` 读取面包店数据,按列映射输出或创建店铺
|
||||
def main():
|
||||
"""
|
||||
从同目录的 `bakeries.csv` 读取面包店数据,按列映射输出或创建店铺
|
||||
|
||||
# 列顺序:`Name,Address,City`
|
||||
# """
|
||||
# api = Api()
|
||||
# csv_path = os.path.join(os.path.dirname(__file__), 'bakeries.csv')
|
||||
# if not os.path.exists(csv_path):
|
||||
# logger.error(f'CSV 文件不存在: {csv_path}')
|
||||
# return
|
||||
列顺序:`Name,Address,City`
|
||||
"""
|
||||
api = Api()
|
||||
csv_path = os.path.join(os.path.dirname(__file__), 'bakeries.csv')
|
||||
if not os.path.exists(csv_path):
|
||||
logger.error(f'CSV 文件不存在: {csv_path}')
|
||||
return
|
||||
|
||||
# with open(csv_path, 'r', encoding='utf-8') as file:
|
||||
# reader = csv.reader(file)
|
||||
# header = next(reader, None)
|
||||
# for row in reader:
|
||||
# if len(row) < 3:
|
||||
# logger.warning(f'行列数不足,跳过: {row}')
|
||||
# continue
|
||||
# shop_name, street, city = row[0], row[1], row[2]
|
||||
# logger.info(f'city: {city}, street: {street}, shop_name: {shop_name}')
|
||||
# api.create_shop(city, street, shop_name)
|
||||
with open(csv_path, 'r', encoding='utf-8') as file:
|
||||
reader = csv.reader(file)
|
||||
header = next(reader, None)
|
||||
for row in reader:
|
||||
if len(row) < 3:
|
||||
logger.warning(f'行列数不足,跳过: {row}')
|
||||
continue
|
||||
shop_name, street, city = row[0], row[1], row[2]
|
||||
if ' (city)' in city:
|
||||
city = city.replace(' (city)', '')
|
||||
if 'Quebec' in city:
|
||||
continue
|
||||
if ',' in city:
|
||||
city = city.split(',')[0]
|
||||
logger.info(f'city: {city}, street: {street}, shop_name: {shop_name}')
|
||||
api.create_shop(city, street, shop_name)
|
||||
|
||||
# def main2():
|
||||
# api = Api()
|
||||
|
||||
Reference in New Issue
Block a user