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
f248e7ab
authored
Sep 18, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add cn file
parent
2ed57ce0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
11 deletions
rs_data.py
rs_data.py
View file @
f248e7ab
...
...
@@ -20,15 +20,15 @@ global_csv_title = ['DistributorPartNumber', 'ManufacturerPartNumber', 'Manufact
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"
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
()
...
...
@@ -36,7 +36,7 @@ conf = config.load_config_map()
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
:
reader
=
csv
.
reader
(
f
)
title
=
[]
...
...
@@ -86,12 +86,66 @@ def handle_hk_csv(file_name):
item_map
[
"price_cn"
]
=
float
(
0
)
ladder_price
.
append
(
item_map
)
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
)
print
(
json_str
)
def
handle_cn_csv
():
pass
...
...
@@ -116,7 +170,7 @@ if __name__ == '__main__':
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)
# 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
):
...
...
@@ -124,13 +178,12 @@ if __name__ == '__main__':
"""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_2, 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
)
# handle_standard_csv(extract_dir + handle_file_name_2)
# handle_standard_csv(extract_dir + handle_file_name_3)
# handle_hk_csv(extract_dir + handle_file_name_1)
handle_cn_csv
(
extract_dir
+
handle_file_name_3
)
"""remove the temp file, close the connection"""
...
...
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