Commit 66f5e99e by 刘豪

hk压缩包自身有问题

parent 22b7fa3c
Showing with 17 additions and 10 deletions
......@@ -198,10 +198,11 @@ def get_supplier_id(supplier_name: str, conf: dict) -> int:
def down_and_handle(ftp_client):
"""download the zip file"""
logger.info("下载压缩包")
ftp_client.download(remote_file_name_1, conf_environment["tmp_file_path"] + local_file_name_1)
extract_dir = conf_environment["tmp_file_path"] + "extract/"
# ftp_client.download(remote_file_name_1, conf_environment["tmp_file_path"] + local_file_name_1)
ftp_client.download(remote_file_name_3, conf_environment["tmp_file_path"] + local_file_name_3)
extract_dir = conf_environment["tmp_file_path"] + "extract/"
if not os.path.exists(extract_dir):
os.makedirs(extract_dir)
......@@ -209,7 +210,7 @@ def down_and_handle(ftp_client):
try:
logger.info("解压压缩包")
file_handle.unzip(conf_environment["tmp_file_path"] + local_file_name_1, extract_dir)
# file_handle.unzip(conf_environment["tmp_file_path"] + local_file_name_1, extract_dir)
file_handle.unzip(conf_environment["tmp_file_path"] + local_file_name_3, extract_dir)
......@@ -219,11 +220,17 @@ def down_and_handle(ftp_client):
if rs_cn_supplier_id == -1 or rs_hk_supplier_id == -1:
logger.info("不支持的supplier_id")
sys.exit("can't query the correct supplier id.")
handle_hk_csv(extract_dir + handle_file_name_1, conf_environment, rs_hk_supplier_id)
# handle_hk_csv(extract_dir + handle_file_name_1, conf_environment, rs_hk_supplier_id)
handle_cn_csv(extract_dir + handle_file_name_3, conf_environment, rs_cn_supplier_id)
except Exception as e:
remove_file(extract_dir)
logger.error("报错:{}, 重试".format(e))
ftp_client = ftp.FTPUtil(host=conf_environment["ftp"]["host"],
port=conf_environment["ftp"]["port"],
passive=True,
username=conf_environment["ftp"]["username"],
password=conf_environment["ftp"]["password"],
logger=logger)
down_and_handle(ftp_client)
return extract_dir
......
import ftplib
from ftplib import FTP
import os
......@@ -13,11 +13,11 @@ class FTPUtil:
username="",
password="",
logger):
ftp = ftplib.FTP()
ftp.connect(host, port)
ftp.login(username, password)
ftp.set_pasv(passive)
self.ftp = ftp
# ftp = ftplib.FTP()
# ftp.connect(host, port)
# ftp.login(username, password)
# ftp.set_pasv(passive)
self.ftp = FTP(host, username, password, timeout=60)
self.logger = logger
def get_connection(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment