Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
my-awesome-project
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
9f693399
authored
Jul 30, 2024
by
larosa
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add script
parent
3d0f35b4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
waldom_data_process_USD.py
waldom_data_process_USD.py
View file @
9f693399
import
csv
import
csv
import
json
import
json
import
logging
import
logging
import
time
logging
.
basicConfig
(
level
=
logging
.
INFO
,
filename
=
'waldom_dollar.log'
,
format
=
'
%(asctime)
s -
%(name)
s -
%(levelname)
s -
%(message)
s'
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
filename
=
'waldom_dollar.log'
,
format
=
'
%(asctime)
s -
%(name)
s -
%(levelname)
s -
%(message)
s'
)
logger
=
logging
.
getLogger
(
'waldom_data_process_USD.py'
)
logger
=
logging
.
getLogger
(
'waldom_data_process_USD.py'
)
...
@@ -30,8 +30,6 @@ class HandleCSV:
...
@@ -30,8 +30,6 @@ class HandleCSV:
first_line
=
[]
first_line
=
[]
reader
=
csv
.
reader
(
f
)
reader
=
csv
.
reader
(
f
)
for
index
,
row
in
enumerate
(
reader
):
for
index
,
row
in
enumerate
(
reader
):
if
index
>
100
:
break
if
index
==
0
:
if
index
==
0
:
first_line
=
row
first_line
=
row
flag
=
self
.
validate
(
first_line
)
flag
=
self
.
validate
(
first_line
)
...
@@ -40,6 +38,7 @@ class HandleCSV:
...
@@ -40,6 +38,7 @@ class HandleCSV:
return
[]
return
[]
else
:
else
:
json_str
=
self
.
generate_json
(
row
,
first_line
)
json_str
=
self
.
generate_json
(
row
,
first_line
)
print
(
json_str
)
result
.
append
(
json_str
)
result
.
append
(
json_str
)
logger
.
info
(
"文件
%
s 已解析"
%
path
)
logger
.
info
(
"文件
%
s 已解析"
%
path
)
return
result
return
result
...
@@ -59,6 +58,7 @@ class HandleCSV:
...
@@ -59,6 +58,7 @@ class HandleCSV:
table
[
'ladder_price'
]
=
[]
table
[
'ladder_price'
]
=
[]
table
[
'supplier_name'
]
=
'Waldom美金'
table
[
'supplier_name'
]
=
'Waldom美金'
table
[
'goods_sn'
]
=
''
table
[
'goods_sn'
]
=
''
batch_sn_map
=
dict
()
for
i
in
range
(
len
(
title
)):
for
i
in
range
(
len
(
title
)):
ladder_item_map
=
dict
()
ladder_item_map
=
dict
()
if
title
[
i
]
in
title_map
:
if
title
[
i
]
in
title_map
:
...
@@ -86,13 +86,28 @@ class HandleCSV:
...
@@ -86,13 +86,28 @@ class HandleCSV:
ladder_item_map
[
'price_cn'
]
=
float
(
0
)
ladder_item_map
[
'price_cn'
]
=
float
(
0
)
table
[
'ladder_price'
]
.
append
(
ladder_item_map
)
table
[
'ladder_price'
]
.
append
(
ladder_item_map
)
elif
title
[
i
]
==
'Date Code'
:
elif
title
[
i
]
==
'Date Code'
:
items
=
str
(
arr
[
i
])
.
split
(
sep
=
";"
)
items_arr
=
str
(
arr
[
i
])
.
split
(
sep
=
";"
)
print
(
items
)
for
j
in
range
(
len
(
items_arr
)):
item
=
items_arr
[
j
]
split_item_arr
=
item
.
split
(
sep
=
"|"
)
if
len
(
split_item_arr
)
==
3
:
number
=
split_item_arr
[
0
]
.
strip
()
year
=
split_item_arr
[
1
]
.
strip
()
if
len
(
number
)
>
0
and
len
(
year
)
>=
4
and
number
.
isdigit
()
and
str
(
year
[
len
(
year
)
-
4
:])
.
isdigit
():
key
=
str
(
year
[
len
(
year
)
-
2
:])
+
"+"
value
=
number
if
key
in
batch_sn_map
:
batch_sn_map
[
key
]
+=
int
(
value
)
else
:
batch_sn_map
[
key
]
=
int
(
value
)
table
[
'batch_sn'
]
=
batch_sn_map
return
json
.
dumps
(
table
,
ensure_ascii
=
False
)
return
json
.
dumps
(
table
,
ensure_ascii
=
False
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
start
=
time
.
time
()
result
=
HandleCSV
()
.
parse
(
'Tianyang_InventoryFeed.csv'
)
result
=
HandleCSV
()
.
parse
(
'Tianyang_InventoryFeed.csv'
)
end
=
time
.
time
()
print
(
"spend time: "
+
str
(
end
-
start
))
...
...
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