Commit 56ec51e3 by 岳巧源

add rs_data

parent 8c69746b
Showing with 18 additions and 14 deletions
......@@ -27,7 +27,7 @@ conf = config.load_config_map()
def handle_hk_csv(file_name, conf: dict):
def handle_hk_csv(file_name, conf: dict, supplier_id: int):
"""handle the HK_cn file"""
p = rabbit_mq.Producer(
user=conf["rabbit_mq"]["producer"]["user"],
......@@ -60,7 +60,7 @@ def handle_hk_csv(file_name, conf: dict):
for i in range(len(row)):
if title[i] == 'DistributorPartNumber':
# TODO origin goods_sn + supplier_id
message_map["goods_sn"] = str(row[i]) + "_"
message_map["goods_sn"] = str(row[i]) + "_" + str(supplier_id)
if title[i] == 'ManufacturerPartNumber':
message_map['goods_name'] = str(row[i])
if title[i] == 'Manufacturer':
......@@ -90,6 +90,7 @@ def handle_hk_csv(file_name, conf: dict):
ladder_price.append(item_map)
message_map["ladder_price"] = ladder_price
message_map["price_is_us"] = True
message_map["supplier_name"] = 'Rs'
json_str = json.dumps(message_map)
p.push(json_str, exchange=conf["rabbit_mq"]["producer"]["rabbit_mq_exchange"],
routing_key=conf["rabbit_mq"]["producer"]["rabbit_mq_routing_key"])
......@@ -97,7 +98,7 @@ def handle_hk_csv(file_name, conf: dict):
def handle_cn_csv(file_name, conf: dict):
def handle_cn_csv(file_name, conf: dict, supplier_id: int):
"""handle the RMB file"""
p = rabbit_mq.Producer(
user=conf["rabbit_mq"]["producer"]["user"],
......@@ -131,7 +132,7 @@ def handle_cn_csv(file_name, conf: dict):
message_map['goods_details'] = ''
for i in range(len(row)):
if title[i] == 'DistributorPartNumber':
message_map["goods_sn"] = str(row[i]) + "_"
message_map["goods_sn"] = str(row[i]) + "_" + str(supplier_id)
if title[i] == 'ManufacturerPartNumber':
message_map['goods_name'] = str(row[i])
if title[i] == 'Manufacturer':
......@@ -160,6 +161,7 @@ def handle_cn_csv(file_name, conf: dict):
ladder_price.append(item_map)
message_map["ladder_price"] = ladder_price
message_map["price_is_us"] = False
message_map["supplier_name"] = 'RS-CN'
json_str = json.dumps(message_map)
p.push(json_str, exchange=conf["rabbit_mq"]["producer"]["rabbit_mq_exchange"],
routing_key=conf["rabbit_mq"]["producer"]["rabbit_mq_routing_key"])
......@@ -208,28 +210,30 @@ if __name__ == '__main__':
if not os.path.exists(conf_environment["tmp_file_path"]):
os.makedirs(conf_environment["tmp_file_path"])
"""download the zip file"""
# ftp_client.download(remote_file_name_1, conf_environment["tmp_file_path"] + local_file_name_1)
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)
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)
"""unzip the zip file"""
# 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)
file_handle.unzip(conf_environment["tmp_file_path"] + local_file_name_3, extract_dir)
"""handle the file and then post to rabbitmq"""
# handle_hk_csv(extract_dir + handle_file_name_1, conf_environment)
handle_cn_csv(extract_dir + handle_file_name_3, conf_environment)
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)
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)
"""remove the temp file, close the connection"""
# remove(extract_dir + handle_file_name_1)
# remove(extract_dir + handle_file_name_3)
# remove(conf_environment["tmp_file_path"] + local_file_name_1)
# remove(conf_environment["tmp_file_path"] + local_file_name_3)
remove(extract_dir + handle_file_name_1)
remove(extract_dir + handle_file_name_3)
remove(conf_environment["tmp_file_path"] + local_file_name_1)
remove(conf_environment["tmp_file_path"] + local_file_name_3)
......
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