提交 80cb5cb4 作者: 丁双波

文件路径特殊字符处理

上级 36713e81
......@@ -61,6 +61,15 @@ def downFile(url,path):
log.error(f"出错了----------{e}")
return False
return fileName
def getPath(str):
str = str.replace(':', '')
str = str.replace(': ', '')
str = str.replace(' ', '')
str = str.replace('"', '')
str = str.replace("'", '')
str = str.replace("/", '')
return str
if __name__ == '__main__':
while True :
selectSql = f"select id,url,website,ftype,stype,ttype from usvsrussia where state=0 order by id asc limit 1"
......@@ -76,14 +85,15 @@ if __name__ == '__main__':
path=r'D:\美国VS俄罗斯制裁'
log.info(f"开始处理{url}----")
if website:
path = os.path.join(path, website)
path = os.path.join(path, getPath(website))
if ftype:
path = os.path.join(path, ftype)
path = os.path.join(path, getPath(ftype))
if stype:
path = os.path.join(path, stype)
path = os.path.join(path, getPath(stype))
if ttype:
path = os.path.join(path, ttype)
path = os.path.join(path, getPath(ttype))
fileName = downFile(url,path)
if fileName:
updateSql = f"update usvsrussia set state=1,pdf_name='{fileName}' ,pdf_path='{escape_string(path)}' where id={id}"
......@@ -96,10 +106,7 @@ if __name__ == '__main__':
else:
log.info("数据处理完毕,程序退出")
break
url = 'https://ofac.treasury.gov/media/931946/download?inline'
log.info(f"{url}----开始下载")
downFile(url)
log.info(f"{url}----开始下载,下载完成")
baseCore.close()
cursor.close()
cnx.close()
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论