gen_sql.py 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2023/02/26 13:12:22
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : 根据list.txt生成执行sql,然后导入sqlite实现批量导入系统
  8. 前期检测list.txt各行是否有效,并维护这个列表
  9. '''
  10. import os,sys,re
  11. # 最新的id
  12. initId=65
  13. def gen(id:int, url:str):
  14. '''生成sql'''
  15. mount_path= url.split("//")[1].split(":")[0]
  16. print("-----------------"+mount_path)
  17. 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', '');"
  18. sql=sql % (id, mount_path, url, url)
  19. sql=sql.replace(r'\"','"')
  20. with open('result.sql','a+',encoding='utf-8') as file:
  21. file.write(sql+"\r\n")
  22. if __name__=='__main__':
  23. with open('list.txt','r',encoding='utf-8') as file:
  24. lines = file.readlines()
  25. for line in lines:
  26. gen(initId, line)
  27. initId=initId+1
  28. # break
  29. print("最后更新id为:"+str(initId))