Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amazon_reports
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
common
amazon_reports
Commits
e3be3a16
Commit
e3be3a16
authored
Apr 03, 2025
by
邱阿朋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(spa): 优化下载报表流程
- 调整等待时间,确保页面加载完成 - 修改文件下载路径和命名规则- 优化文件处理流程,移除不必要的临时文件 - 异常处理,捕获可能的错误
parent
b87a00dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
14 deletions
+13
-14
spa.py
app/vc/spa.py
+13
-14
No files found.
app/vc/spa.py
View file @
e3be3a16
...
...
@@ -38,7 +38,8 @@ class Spa(AutoInterface):
self
.
__page_get
(
f
"hz/vendor/members/coop?searchText={invoice_id}"
)
# 点击选项卡
self
.
page
.
ele
(
"#a-autoid-2-announce"
)
.
click
()
# 下载报表
self
.
page
.
wait
(
2
)
# 点击下载报表选项
self
.
page
.
ele
(
f
"#invoiceDownloads-{invoice_id}_2"
)
.
click
()
self
.
page
.
wait
(
1
)
# 获取报表表单内容
...
...
@@ -69,17 +70,12 @@ class Spa(AutoInterface):
return
None
for
link
in
links
:
# 解析链接中的查询参数
parsed_url
=
urlparse
(
link
)
query_params
=
parse_qs
(
parsed_url
.
query
)
# 提取 filename 参数
filename
=
query_params
.
get
(
'fileName'
,
[
'未找到文件名'
])[
0
]
report_file_tmp_dir
=
os
.
getcwd
()
+
f
"
\\
spa
\\
{invoice_id}
\\
{filename}
\\
"
host
=
domain
.
switch_domain
(
self
.
country
)
report_file
=
report_file_tmp_dir
+
"BackupReport.xls"
host
=
domain
.
switch_domain
(
self
.
country
)
.
rstrip
(
'/'
)
report_file
=
os
.
path
.
join
(
os
.
getcwd
(),
"BackupReport.xls"
)
while
True
:
self
.
page
.
download
(
host
+
link
,
report_file_tmp_dir
,
show_msg
=
False
)
is_down
=
file
.
wait_for_downloads
(
report_file
,
60
)
file_link
=
host
+
link
self
.
page
.
get
(
file_link
,
retry
=
0
)
is_down
=
file
.
wait_for_downloads
(
report_file
,
20
)
if
is_down
:
break
self
.
logger
.
warning
(
f
"下载 {invoice_id} 失败,重新下载"
)
...
...
@@ -92,18 +88,21 @@ class Spa(AutoInterface):
# 判断头文件是否满足读取条件,不满足删除文件夹
header_is_normal
=
any
(
column
in
headers
for
column
in
column_names_to_check
)
if
not
header_is_normal
:
os
.
remove
(
report_file
)
continue
save_report_file
=
os
.
path
.
join
(
os
.
getcwd
(),
"spa"
,
invoice_id
,
"BackupReport.xls"
)
file
.
move_file
(
report_file
,
save_report_file
)
# 创建 ExcelFile 对象
excel_file
=
pd
.
ExcelFile
(
report_file
)
excel_file
=
pd
.
ExcelFile
(
save_
report_file
)
# 获取所有工作表名称
sheet_names
=
excel_file
.
sheet_names
for
sheet_name
in
sheet_names
:
df
=
pd
.
read_excel
(
report_file
,
sheet_name
=
sheet_name
)
df
=
pd
.
read_excel
(
save_
report_file
,
sheet_name
=
sheet_name
)
data
=
df
[
df
[
'Asin'
]
.
notna
()]
excel
.
save_xls
(
data
,
file_name
,
sheet_name
)
return
pd
.
read_excel
(
file_name
,
sheet_name
=
None
)
except
ValueError
:
except
ValueError
as
e
:
pass
def
__process_large_items
(
self
,
item_list
,
relation_data
,
coop
):
...
...
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