Commit 52554d47 by 岳巧源

sku upload

parent f7fd1d21
Showing with 78 additions and 13 deletions
import csv
import json
import os.path import os.path
import sys import sys
...@@ -5,6 +7,18 @@ import config ...@@ -5,6 +7,18 @@ import config
from utils import ftp from utils import ftp
from utils import file_handle from utils import file_handle
global_csv_title = ['DistributorPartNumber', 'ManufacturerPartNumber', 'Manufacturer', 'Description', 'ROHS', 'ProductUrl',
'QuantityAvailable', 'PriceQuantity', 'IMAGE_URL', 'PRODUCT_TYPE',
'BASE_UOM', 'SALES_UOM', 'PACK_SIZE', 'HKD_1_Price', 'HKD_2_Price', 'HKD_3_Price', 'HKD_4_Price', 'HKD_5_Price',
'ATTRIBUTE_1_NAME', 'ATTRIBUTE_2_NAME', 'ATTRIBUTE_3_NAME',
'ATTRIBUTE_4_NAME', 'ATTRIBUTE_5_NAME', 'ATTRIBUTE_6_NAME', 'ATTRIBUTE_7_NAME', 'ATTRIBUTE_8_NAME', 'ATTRIBUTE_9_NAME',
'ATTRIBUTE_10_NAME', 'ATTRIBUTE_11_NAME', 'ATTRIBUTE_12_NAME',
'ATTRIBUTE_13_NAME', 'ATTRIBUTE_14_NAME', 'ATTRIBUTE_15_NAME', 'ATTRIBUTE_1_VALUE', 'ATTRIBUTE_2_VALUE', 'ATTRIBUTE_3_VALUE', 'ATTRIBUTE_4_VALUE',
'ATTRIBUTE_5_VALUE', 'ATTRIBUTE_6_VALUE', 'ATTRIBUTE_7_VALUE', 'ATTRIBUTE_8_VALUE', 'ATTRIBUTE_9_VALUE', 'ATTRIBUTE_10_VALUE', 'ATTRIBUTE_11_VALUE',
'ATTRIBUTE_12_VALUE', 'ATTRIBUTE_13_VALUE', 'ATTRIBUTE_14_VALUE', 'ATTRIBUTE_15_VALUE', 'STOCK_QTY_GB', 'SHIPPING_WEIGHT']
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_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"
...@@ -13,12 +27,58 @@ local_file_name_1 = "rs_components_HK-cn_chiplink.csv.zip" ...@@ -13,12 +27,58 @@ 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_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_2 = "rs_components_HK-en_chiplink.csv"
handle_file_name_3 = "rs_components_cn_chiplink.csv"
conf = config.load_config_map() conf = config.load_config_map()
def handle_csv():
pass def handle_standard_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):
if index > 10:
break
if index == 0:
title = row
continue
message_map = dict()
ladder_number = []
ladder_price_item = dict()
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]
if title[i] == 'ManufacturerPartNumber':
message_map['goods_name'] = row[i]
if title[i] == 'Manufacturer':
message_map['brand_name'] = row[i]
if title[i] == 'QuantityAvailable':
message_map['stock'] = row[i]
if title[i] == 'PriceQuantity':
ladder_number = row[i].split(sep="|")
# TODO not sure about the price.
message_map['moq'] = ladder_number[0]
if title[i] == 'PACK_SIZE':
message_map['multiple'] = row[i]
message_map['mpq'] = row[i]
if title[i] == 'IMAGE_URL':
message_map['goods_images'] = row[i]
json_str = json.dumps(message_map)
print(json_str)
...@@ -33,6 +93,8 @@ if __name__ == '__main__': ...@@ -33,6 +93,8 @@ if __name__ == '__main__':
username=conf_environment["ftp"]["username"], username=conf_environment["ftp"]["username"],
password=conf_environment["ftp"]["password"] password=conf_environment["ftp"]["password"]
) )
if not os.path.exists(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_2, conf_environment["tmp_file_path"] + local_file_name_2)
...@@ -47,7 +109,9 @@ if __name__ == '__main__': ...@@ -47,7 +109,9 @@ if __name__ == '__main__':
# 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_standard_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)
"""remove the temp file, close the connection""" """remove the temp file, close the connection"""
......
{ {
"goods_sn": "", "goods_sn": "1 col",
"goods_name": "", "goods_name": " 2 col",
"brand_name": "", "brand_name": "3 col",
"stock": "", "stock": "quanti availble",
"moq": "", "moq": "== mpq || ladder【0】",
"ladder_price": "", "ladder_price": "pricequantil",
"price_is_us": "", "price_is_us": "",
"supplier_name": "", "supplier_name": "",
"multiple": "", "multiple": "moq",
"batch_sn": "", "batch_sn": "null",
"eccn": "", "eccn": "null",
"supplier_id": "", "supplier_id": "",
"mpq": "", "mpq": "package size",
"goods_details": "", "goods_details": "",
"goods_images": "" "goods_images": ""
} }
\ No newline at end of file
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