123456789101112131415161718192021222324252627282930313233 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- '''
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2023/02/26 13:12:22
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc : 根据list.txt生成执行sql,然后导入sqlite实现批量导入系统
- 前期检测list.txt各行是否有效,并维护这个列表
- '''
- import os,sys,re
- # 最新的id
- initId=65
- def gen(id:int, url:str):
- '''生成sql'''
- mount_path= url.split("//")[1].split(":")[0]
- print("-----------------"+mount_path)
- sql = "INSERT INTO \"main\".\"x_storages\" (\"id\", \"mount_path\", \"order\", \"driver\", \"cache_expiration\", \"status\", \"addition\", \"remark\", \"modified\", \"disabled\", \"order_by\", \"order_direction\", \"extract_folder\", \"web_proxy\", \"webdav_policy\", \"down_proxy_url\") VALUES (%s, '/NetDriverA/%s', 0, 'AList V3', 30, 'work', '{\"root_folder_path\":\"/\",\"url\":\"%s\",\"password\":\"\",\"access_token\":\"\"}', '%s', '2023-02-26 20:47:36.498219296+08:00', 0, '', '', '', 0, '302_redirect', '');"
- sql=sql % (id, mount_path, url, url)
- sql=sql.replace(r'\"','"')
- with open('result.sql','a+',encoding='utf-8') as file:
- file.write(sql+"\r\n")
-
- if __name__=='__main__':
- with open('list.txt','r',encoding='utf-8') as file:
- lines = file.readlines()
- for line in lines:
- gen(initId, line)
- initId=initId+1
- # break
- print("最后更新id为:"+str(initId))
|