代码拉取完成,页面将自动刷新
import sqlite3
import pandas as pd
from argparse import ArgumentParser
from tqdm.rich import tqdm
from loguru import logger
def short_id(id: str):
new_id = id.removeprefix('detail_')
new_id = new_id.removeprefix('corner_')
new_id = new_id.removeprefix('number_')
return new_id
def main():
p = ArgumentParser()
p.add_argument('--path', type=str, help='path to pacenotes.csv')
p.add_argument('--db', type=str, help='path to db')
args = vars(p.parse_args())
df = pd.read_csv(args['path']) # pacenotes.csv
df.sort_values(by='Id', inplace=True)
df.reset_index(drop=True, inplace=True)
data_pacenote = []
data_pacenote_filenames_primary = []
data_pacenote_filenames = []
rows = list(df.iterrows())
for i, row in tqdm(rows):
data_pacenote.append((i, row['Description']))
data_pacenote_filenames_primary.append((i, short_id(row['Id']), True))
data_pacenote_filenames.append((i, row['Id'], False))
logger.info(f'got {len(data_pacenote)} pacenotes and {len(data_pacenote_filenames)} filenames')
conn = sqlite3.connect(args['db'])
c = conn.cursor()
c.executemany('INSERT INTO pacenote(`id`, `description`) VALUES (?, ?)', data_pacenote)
c.executemany('INSERT INTO pacenote_filenames(`id`, `filename`, `is_primary`) VALUES (?, ?, ?)', data_pacenote_filenames_primary)
c.executemany('INSERT INTO pacenote_filenames(`id`, `filename`, `is_primary`) VALUES (?, ?, ?)', data_pacenote_filenames)
conn.commit()
logger.info('done')
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。