提交 80cb5cb4 作者: 丁双波

文件路径特殊字符处理

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