Commit f248e7ab by 岳巧源

add cn file

parent 2ed57ce0
Showing with 64 additions and 11 deletions
...@@ -20,15 +20,15 @@ global_csv_title = ['DistributorPartNumber', 'ManufacturerPartNumber', 'Manufact ...@@ -20,15 +20,15 @@ global_csv_title = ['DistributorPartNumber', 'ManufacturerPartNumber', 'Manufact
remote_file_name_1 = "/rs_components_HK-cn_chiplink.csv.zip" remote_file_name_1 = "/rs_components_HK-cn_chiplink.csv.zip"
remote_file_name_2 = "/rs_components_HK-en_chiplink.csv.zip"
remote_file_name_3 = "/rs_components_cn_chiplink.csv.zip" remote_file_name_3 = "/rs_components_cn_chiplink.csv.zip"
local_file_name_1 = "rs_components_HK-cn_chiplink.csv.zip" local_file_name_1 = "rs_components_HK-cn_chiplink.csv.zip"
local_file_name_2 = "rs_components_HK-en_chiplink.csv.zip"
local_file_name_3 = "rs_components_cn_chiplink.csv.zip" local_file_name_3 = "rs_components_cn_chiplink.csv.zip"
handle_file_name_1 = "rs_components_HK-cn_chiplink.csv" handle_file_name_1 = "rs_components_HK-cn_chiplink.csv"
handle_file_name_2 = "rs_components_HK-en_chiplink.csv"
handle_file_name_3 = "rs_components_cn_chiplink.csv" handle_file_name_3 = "rs_components_cn_chiplink.csv"
conf = config.load_config_map() conf = config.load_config_map()
...@@ -36,7 +36,7 @@ conf = config.load_config_map() ...@@ -36,7 +36,7 @@ conf = config.load_config_map()
def handle_hk_csv(file_name): def handle_hk_csv(file_name):
"""handle the csv file witch separator is ',' """ """handle the HK_cn file"""
with open(file_name, errors='ignore') as f: with open(file_name, errors='ignore') as f:
reader = csv.reader(f) reader = csv.reader(f)
title = [] title = []
...@@ -86,12 +86,66 @@ def handle_hk_csv(file_name): ...@@ -86,12 +86,66 @@ def handle_hk_csv(file_name):
item_map["price_cn"] = float(0) item_map["price_cn"] = float(0)
ladder_price.append(item_map) ladder_price.append(item_map)
message_map["ladder_price"] = ladder_price message_map["ladder_price"] = ladder_price
message_map["price_is_us"] = True
json_str = json.dumps(message_map)
print(json_str)
def handle_cn_csv(file_name):
"""handle the RMB file"""
with open(file_name, errors='ignore') as f:
reader = csv.reader(f)
title = []
for index, row in enumerate(reader):
# TODO remember to delete this code.
if index > 10:
break
if index == 0:
title = row
continue
message_map = dict()
ladder_number = []
ladder_price = []
prices = []
for i in range(len(row)):
message_map['batch_sn'] = {}
message_map['eccn'] = ''
message_map['goods_details'] = ''
if title[i] == 'DistributorPartNumber':
# TODO origin goods_sn + supplier_id
message_map["goods_sn"] = str(row[i]) + "_"
if title[i] == 'ManufacturerPartNumber':
message_map['goods_name'] = str(row[i])
if title[i] == 'Manufacturer':
message_map['brand_name'] = str(row[i])
if title[i] == 'QuantityAvailable':
message_map['stock'] = str(row[i])
if title[i] == 'PriceQuantity':
ladder_number = row[i].split(sep="|")
message_map['moq'] = str(ladder_number[0])
if title[i] == 'PACK_SIZE':
message_map['multiple'] = str(row[i])
message_map['mpq'] = str(row[i])
if title[i] == 'IMAGE_URL':
message_map['goods_images'] = str(row[i])
if title[i] == 'RMB_1_Price' or title[i] == 'RMB_2_Price' or \
title[i] == 'RMB_3_Price' or title[i] == 'RMB_4_Price' or \
title[i] == 'RMB_5_Price':
if row[i] == '' or len(row[i]) == 0:
continue
prices.append(row[i])
for i in range(min(len(ladder_number), len(prices))):
item_map = dict()
item_map["purchases"] = int(ladder_number[i])
item_map["price_us"] = float(0)
item_map["price_cn"] = float(prices[i])
ladder_price.append(item_map)
message_map["ladder_price"] = ladder_price
message_map["price_is_us"] = False
json_str = json.dumps(message_map) json_str = json.dumps(message_map)
print(json_str) print(json_str)
def handle_cn_csv():
pass
...@@ -116,7 +170,7 @@ if __name__ == '__main__': ...@@ -116,7 +170,7 @@ if __name__ == '__main__':
os.makedirs(conf_environment["tmp_file_path"]) os.makedirs(conf_environment["tmp_file_path"])
"""download the zip file""" """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_2, conf_environment["tmp_file_path"] + local_file_name_2)
# 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/" extract_dir = conf_environment["tmp_file_path"] + "extract/"
if not os.path.exists(extract_dir): if not os.path.exists(extract_dir):
...@@ -124,13 +178,12 @@ if __name__ == '__main__': ...@@ -124,13 +178,12 @@ if __name__ == '__main__':
"""unzip the zip file""" """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_2, 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 the file and then post to rabbitmq"""
handle_hk_csv(extract_dir + handle_file_name_1) # handle_hk_csv(extract_dir + handle_file_name_1)
# handle_standard_csv(extract_dir + handle_file_name_2) handle_cn_csv(extract_dir + handle_file_name_3)
# handle_standard_csv(extract_dir + handle_file_name_3)
"""remove the temp file, close the connection""" """remove the temp file, close the connection"""
......
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