Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
europa-erp-python
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
52554d47
authored
Sep 18, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
sku upload
parent
f7fd1d21
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
13 deletions
rs_data.py
template/sku_data.json
rs_data.py
View file @
52554d47
import
csv
import
json
import
os.path
import
sys
...
...
@@ -5,6 +7,18 @@ import config
from
utils
import
ftp
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_2
=
"/rs_components_HK-en_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"
local_file_name_2
=
"rs_components_HK-en_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
()
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__':
username
=
conf_environment
[
"ftp"
][
"username"
],
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"""
# 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)
...
...
@@ -47,7 +109,9 @@ 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_standard_csv(extract_dir + handle_file_name_2)
# handle_standard_csv(extract_dir + handle_file_name_3)
"""remove the temp file, close the connection"""
...
...
template/sku_data.json
View file @
52554d47
{
"goods_sn"
:
""
,
"goods_name"
:
""
,
"brand_name"
:
""
,
"stock"
:
""
,
"moq"
:
""
,
"ladder_price"
:
""
,
"goods_sn"
:
"
1 col
"
,
"goods_name"
:
"
2 col
"
,
"brand_name"
:
"
3 col
"
,
"stock"
:
"
quanti availble
"
,
"moq"
:
"
== mpq || ladder【0】
"
,
"ladder_price"
:
"
pricequantil
"
,
"price_is_us"
:
""
,
"supplier_name"
:
""
,
"multiple"
:
""
,
"batch_sn"
:
""
,
"eccn"
:
""
,
"multiple"
:
"
moq
"
,
"batch_sn"
:
"
null
"
,
"eccn"
:
"
null
"
,
"supplier_id"
:
""
,
"mpq"
:
""
,
"mpq"
:
"
package size
"
,
"goods_details"
:
""
,
"goods_images"
:
""
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment