Commit 389fb0e9 by 刘豪

update

parent 66f5e99e
Showing with 29 additions and 24 deletions
......@@ -194,25 +194,36 @@ def get_supplier_id(supplier_name: str, conf: dict) -> int:
db.close()
return supplier_id
def down_cn(ftp_client, extract_dir):
"""download the zip file"""
logger.info("下载cn压缩包")
ftp_client.download(remote_file_name_3, conf_environment["tmp_file_path"] + local_file_name_3)
"""unzip the zip file"""
try:
logger.info("解压压缩包")
file_handle.unzip(conf_environment["tmp_file_path"] + local_file_name_3, extract_dir)
"""handle the file and then post to rabbitmq"""
rs_hk_supplier_id = get_supplier_id(supplier_name='Rs', conf=conf_environment)
rs_cn_supplier_id = get_supplier_id(supplier_name='RS-CN', conf=conf_environment)
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_cn_csv(extract_dir + handle_file_name_3, conf_environment, rs_cn_supplier_id)
except Exception as e:
logger.error("报错:{}".format(e))
def down_and_handle(ftp_client):
def down_hk(ftp_client, extract_dir):
"""download the zip file"""
logger.info("下载压缩包")
extract_dir = conf_environment["tmp_file_path"] + "extract/"
# ftp_client.download(remote_file_name_1, conf_environment["tmp_file_path"] + local_file_name_1)
logger.info("下载hk压缩包")
ftp_client.download(remote_file_name_3, conf_environment["tmp_file_path"] + local_file_name_3)
ftp_client.download(remote_file_name_1, conf_environment["tmp_file_path"] + local_file_name_1)
if not os.path.exists(extract_dir):
os.makedirs(extract_dir)
"""unzip the zip file"""
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_3, extract_dir)
logger.info("解压hk压缩包")
file_handle.unzip(conf_environment["tmp_file_path"] + local_file_name_1, extract_dir)
"""handle the file and then post to rabbitmq"""
rs_hk_supplier_id = get_supplier_id(supplier_name='Rs', conf=conf_environment)
......@@ -220,19 +231,9 @@ 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_cn_csv(extract_dir + handle_file_name_3, conf_environment, rs_cn_supplier_id)
handle_hk_csv(extract_dir + handle_file_name_1, conf_environment, rs_hk_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
logger.error("报错:{}".format(e))
def remove_file(extract_dir):
"""remove the temp file, close the connection"""
......@@ -251,7 +252,11 @@ def run():
logger = logger)
if not os.path.exists(conf_environment["tmp_file_path"]):
os.makedirs(conf_environment["tmp_file_path"])
extract_dir = down_and_handle(ftp_client)
extract_dir = conf_environment["tmp_file_path"] + "extract/"
if not os.path.exists(extract_dir):
os.makedirs(extract_dir)
down_cn(ftp_client, extract_dir)
down_hk(ftp_client, extract_dir)
remove_file(extract_dir)
logger.info("运行完成")
......
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