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
8c69746b
authored
Sep 18, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add pymysql
parent
422acdad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
20 deletions
config.json
rs_data.py
config.json
View file @
8c69746b
...
...
@@ -17,6 +17,13 @@
"port"
:
2111
,
"password"
:
"rs2024Sl00293sOoj"
,
"username"
:
"rs"
},
"mysql"
:
{
"host"
:
"192.168.1.238"
,
"user"
:
"europa_erp"
,
"password"
:
"europa_erp#zsyM"
,
"port"
:
3306
,
"database"
:
"europa_erp"
}
},
"prod"
:
{
...
...
@@ -37,6 +44,13 @@
"port"
:
2111
,
"password"
:
"rs2024Sl00293sOoj"
,
"username"
:
"rs"
},
"mysql"
:
{
"host"
:
"erp.chiplinks.db"
,
"user"
:
"antXST"
,
"password"
:
"Antxs@#$paf2iOjsft"
,
"port"
:
3306
,
"database"
:
"europa_erp"
}
},
"local"
:
{
...
...
@@ -57,6 +71,13 @@
"port"
:
2111
,
"password"
:
"rs2024Sl00293sOoj"
,
"username"
:
"rs"
},
"mysql"
:
{
"host"
:
"192.168.1.238"
,
"user"
:
"europa_erp"
,
"password"
:
"europa_erp#zsyM"
,
"port"
:
3306
,
"database"
:
"europa_erp"
}
}
}
\ No newline at end of file
rs_data.py
View file @
8c69746b
...
...
@@ -2,20 +2,12 @@ import csv
import
json
import
os.path
import
sys
import
pymysql
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'
]
from
utils
import
rabbit_mq
...
...
@@ -35,14 +27,25 @@ conf = config.load_config_map()
def
handle_hk_csv
(
file_name
):
def
handle_hk_csv
(
file_name
,
conf
:
dict
):
"""handle the HK_cn file"""
p
=
rabbit_mq
.
Producer
(
user
=
conf
[
"rabbit_mq"
][
"producer"
][
"user"
],
password
=
conf
[
"rabbit_mq"
][
"producer"
][
"password"
],
host
=
conf
[
"rabbit_mq"
][
"producer"
][
"host"
],
port
=
conf
[
"rabbit_mq"
][
"producer"
][
"port"
],
queue_name
=
conf
[
"rabbit_mq"
][
"producer"
][
"queue_name"
],
durable
=
True
,
exchange
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_exchange"
],
routing_key
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_routing_key"
]
)
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
>
1
0
:
if
index
>
1
:
break
if
index
==
0
:
title
=
row
...
...
@@ -88,19 +91,31 @@ def handle_hk_csv(file_name):
message_map
[
"ladder_price"
]
=
ladder_price
message_map
[
"price_is_us"
]
=
True
json_str
=
json
.
dumps
(
message_map
)
print
(
json_str
)
p
.
push
(
json_str
,
exchange
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_exchange"
],
routing_key
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_routing_key"
])
p
.
close
()
def
handle_cn_csv
(
file_name
):
def
handle_cn_csv
(
file_name
,
conf
:
dict
):
"""handle the RMB file"""
p
=
rabbit_mq
.
Producer
(
user
=
conf
[
"rabbit_mq"
][
"producer"
][
"user"
],
password
=
conf
[
"rabbit_mq"
][
"producer"
][
"password"
],
host
=
conf
[
"rabbit_mq"
][
"producer"
][
"host"
],
port
=
conf
[
"rabbit_mq"
][
"producer"
][
"port"
],
queue_name
=
conf
[
"rabbit_mq"
][
"producer"
][
"queue_name"
],
durable
=
True
,
exchange
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_exchange"
],
routing_key
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_routing_key"
]
)
with
open
(
file_name
,
mode
=
'r'
,
errors
=
'ignore'
)
as
f
:
reader
=
f
.
readlines
()
title
=
[]
for
j
in
range
(
len
(
reader
)):
# TODO remember to delete this code.
if
j
>
1
0
:
if
j
>
1
:
break
data
=
reader
[
j
]
data
=
data
.
replace
(
"
\n
"
,
''
)
row
=
data
.
split
(
sep
=
'
\t
'
)
...
...
@@ -146,7 +161,36 @@ def handle_cn_csv(file_name):
message_map
[
"ladder_price"
]
=
ladder_price
message_map
[
"price_is_us"
]
=
False
json_str
=
json
.
dumps
(
message_map
)
print
(
json_str
)
p
.
push
(
json_str
,
exchange
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_exchange"
],
routing_key
=
conf
[
"rabbit_mq"
][
"producer"
][
"rabbit_mq_routing_key"
])
p
.
close
()
def
remove
(
path
):
if
os
.
path
.
exists
(
path
):
os
.
remove
(
path
)
def
get_supplier_id
(
supplier_name
:
str
,
conf
:
dict
)
->
int
:
db
=
pymysql
.
connect
(
host
=
conf
[
"mysql"
][
"host"
],
user
=
conf
[
"mysql"
][
"user"
],
password
=
conf
[
"mysql"
][
"password"
],
database
=
conf
[
"mysql"
][
"database"
],
port
=
conf
[
"mysql"
][
"port"
]
)
cursor
=
db
.
cursor
()
query
=
"select * from erp_supplier where supplier_name =
%
s"
param
=
(
supplier_name
,)
supplier_id
=
-
1
try
:
cursor
.
execute
(
query
,
args
=
param
)
results
=
cursor
.
fetchall
()
row
=
results
[
0
]
supplier_id
=
int
(
row
[
0
])
except
Exception
as
e
:
pass
finally
:
db
.
close
()
return
supplier_id
...
...
@@ -177,12 +221,15 @@ 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_hk_csv(extract_dir + handle_file_name_1)
handle_cn_csv
(
extract_dir
+
handle_file_name_3
)
# handle_hk_csv(extract_dir + handle_file_name_1
, conf_environment
)
handle_cn_csv
(
extract_dir
+
handle_file_name_3
,
conf_environment
)
"""remove the temp file, close the connection"""
# remove(extract_dir + handle_file_name_1)
# remove(extract_dir + handle_file_name_3)
# remove(conf_environment["tmp_file_path"] + local_file_name_1)
# remove(conf_environment["tmp_file_path"] + local_file_name_3)
...
...
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