Commit 2ed57ce0 by 岳巧源

add hk_cn

parent 52554d47
Showing with 32 additions and 13 deletions
......@@ -35,12 +35,13 @@ conf = config.load_config_map()
def handle_standard_csv(file_name):
def handle_hk_csv(file_name):
"""handle the csv file witch separator is ',' """
with open(file_name, errors='ignore') as f:
reader = csv.reader(f)
title = []
for index, row in enumerate(reader):
# TODO remember to delete.
if index > 10:
break
if index == 0:
......@@ -48,32 +49,50 @@ def handle_standard_csv(file_name):
continue
message_map = dict()
ladder_number = []
ladder_price_item = dict()
ladder_price = []
prices = []
for i in range(len(row)):
message_map['batch_sn'] = {}
message_map['eccn'] = ''
message_map['goods_details'] = ''
if title[i] == 'DistributorPartNumber':
message_map["goods_sn"] = row[i]
# TODO origin goods_sn + supplier_id
message_map["goods_sn"] = str(row[i]) + "_"
if title[i] == 'ManufacturerPartNumber':
message_map['goods_name'] = row[i]
message_map['goods_name'] = str(row[i])
if title[i] == 'Manufacturer':
message_map['brand_name'] = row[i]
message_map['brand_name'] = str(row[i])
if title[i] == 'QuantityAvailable':
message_map['stock'] = row[i]
message_map['stock'] = str(row[i])
if title[i] == 'PriceQuantity':
ladder_number = row[i].split(sep="|")
# TODO not sure about the price.
message_map['moq'] = ladder_number[0]
message_map['moq'] = str(ladder_number[0])
if title[i] == 'PACK_SIZE':
message_map['multiple'] = row[i]
message_map['mpq'] = row[i]
message_map['multiple'] = str(row[i])
message_map['mpq'] = str(row[i])
if title[i] == 'IMAGE_URL':
message_map['goods_images'] = row[i]
message_map['goods_images'] = str(row[i])
# the price is hkd, but store in 'usd' column.
if title[i] == 'HKD_1_Price' or title[i] == 'HKD_2_Price' \
or title[i] == 'HKD_3_Price' or title[i] == 'HKD_4_Price' \
or title[i] == 'HKD_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(prices[i])
item_map["price_cn"] = float(0)
ladder_price.append(item_map)
message_map["ladder_price"] = ladder_price
json_str = json.dumps(message_map)
print(json_str)
def handle_cn_csv():
pass
......@@ -109,7 +128,7 @@ if __name__ == '__main__':
# file_handle.unzip(conf_environment["tmp_file_path"] + local_file_name_3, extract_dir)
"""handle the file and then post to rabbitmq"""
handle_standard_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_standard_csv(extract_dir + handle_file_name_3)
......
{
"goods_sn": "1 col",
"goods_sn": "1 col ",
"goods_name": " 2 col",
"brand_name": "3 col",
"stock": "quanti availble",
......
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