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
fe4c52b5
Commit
fe4c52b5
authored
Oct 24, 2024
by
邱阿朋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多国家
parent
4a31fbe6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
43 deletions
+98
-43
coop.py
coop.py
+25
-12
domain.py
helper/domain.py
+17
-0
invoices.py
invoices.py
+33
-20
returns.py
returns.py
+23
-11
No files found.
coop.py
View file @
fe4c52b5
...
...
@@ -10,7 +10,7 @@ from DrissionPage import ChromiumPage
from
DrissionPage.errors
import
ElementNotFoundError
from
lxml
import
etree
from
helper
import
helper
,
excel
,
file
from
helper
import
helper
,
excel
,
file
,
domain
page
=
ChromiumPage
()
page
.
set
.
load_mode
.
eager
()
...
...
@@ -24,6 +24,12 @@ helper.make_dir(download_path)
page
.
set
.
download_path
(
download_path
)
def
page_get
(
url
):
host
=
domain
.
switch_domain
(
country
)
full_url
=
host
+
url
page
.
get
(
full_url
,
timeout
=
3
)
def
sku_relations
():
relations_dict
=
{}
df
=
pd
.
read_excel
(
'relations.xlsx'
)
...
...
@@ -37,14 +43,14 @@ def sku_relations():
def
export_list_read_data
():
file_name
=
"ContraCogsInvoices.xls"
if
not
os
.
path
.
isfile
(
file_name
):
#
raise FileNotFoundError(f"{file_name},文件不存在")
page
.
get
(
"https://vendorcentral.amazon.com/
hz/vendor/members/coop?ref_=vc_xx_subNav"
)
# 全选
page
.
ele
(
"#select-all"
)
.
click
()
# 点击选项卡
page
.
ele
(
"#cc-invoice-actions-dropdown"
)
.
click
()
# 点击下载报表
page
.
ele
(
"#cc-invoice-actions-dropdown_2"
)
.
click
.
to_download
()
.
wait
()
raise
FileNotFoundError
(
f
"{file_name},文件不存在"
)
# page_get("
hz/vendor/members/coop?ref_=vc_xx_subNav")
#
#
全选
#
page.ele("#select-all").click()
#
#
点击选项卡
#
page.ele("#cc-invoice-actions-dropdown").click()
#
#
点击下载报表
#
page.ele("#cc-invoice-actions-dropdown_2").click.to_download().wait()
return
pd
.
read_excel
(
file_name
,
engine
=
'xlrd'
)
...
...
@@ -52,7 +58,7 @@ def export_list_read_data():
def
get_report_table_html
(
invoice_id
):
while
True
:
try
:
page
.
get
(
f
"https://vendorcentral.amazon.com/
hz/vendor/members/coop?searchText={invoice_id}"
)
page
_get
(
f
"
hz/vendor/members/coop?searchText={invoice_id}"
)
# 点击选项卡
page
.
ele
(
"#a-autoid-2-announce"
)
.
click
()
# 下载报表
...
...
@@ -69,6 +75,7 @@ def get_report_table_html(invoice_id):
print
(
"元素未找到,刷新网页"
)
page
.
refresh
()
def
export_item_read_data
(
invoice_id
):
file_name
=
f
"coop
\\
{invoice_id}.xlsx"
if
os
.
path
.
isfile
(
file_name
):
...
...
@@ -87,7 +94,8 @@ def export_item_read_data(invoice_id):
# 提取 filename 参数
filename
=
query_params
.
get
(
'fileName'
,
[
'未找到文件名'
])[
0
]
report_file_tmp_dir
=
f
"coop
\\
{invoice_id}
\\
{filename}
\\
"
page
.
download
(
"https://vendorcentral.amazon.com"
+
link
,
report_file_tmp_dir
,
show_msg
=
True
)
host
=
domain
.
switch_domain
(
country
)
page
.
download
(
host
+
link
,
report_file_tmp_dir
,
show_msg
=
True
)
report_file
=
report_file_tmp_dir
+
"BackupReport.xls"
file
.
wait_for_downloads
(
report_file
)
...
...
@@ -114,7 +122,6 @@ def export_item_read_data(invoice_id):
def
main
():
relation_data
=
sku_relations
()
# 获取 ASIN 与 SKU 的对应关系数据
coop_list
=
export_list_read_data
()
# 获取合作数据列表
coop_list
=
coop_list
[:
10
]
print
(
f
"共计:{len(coop_list)} 条数据"
)
i
=
0
...
...
@@ -199,6 +206,12 @@ def main():
if
__name__
==
'__main__'
:
try
:
country
=
helper
.
get_input_with_default
(
"国家"
,
"usa"
)
if
country
is
None
:
raise
Exception
(
"请选择国家"
)
main
()
except
KeyboardInterrupt
:
pass
except
Exception
as
e
:
print
(
e
)
helper/domain.py
0 → 100644
View file @
fe4c52b5
# coding: utf-8
def
switch_domain
(
country
):
domain
=
"https://vendorcentral.amazon.com/"
if
country
==
"jp"
:
domain
=
"https://vendorcentral.amazon.co.jp/"
if
country
==
"uk"
:
domain
=
"https://vendorcentral.amazon.co.uk/"
if
country
==
"fr"
:
domain
=
"https://vendorcentral.amazon.fr/"
if
country
==
"ca"
:
domain
=
"https://vendorcentral.amazon.ca/"
if
country
==
"mx"
:
domain
=
"https://vendorcentral.amazon.com.mx/"
return
domain
invoices.py
View file @
fe4c52b5
...
...
@@ -10,7 +10,7 @@ from DrissionPage import ChromiumPage
from
DrissionPage.errors
import
ElementNotFoundError
from
lxml
import
etree
from
helper
import
helper
,
excel
,
file
from
helper
import
helper
,
excel
,
file
,
domain
page
=
ChromiumPage
()
page
.
set
.
load_mode
.
normal
()
...
...
@@ -26,6 +26,12 @@ page.set.download_path(download_path)
warnings
.
filterwarnings
(
"ignore"
,
category
=
UserWarning
,
module
=
"openpyxl"
)
def
page_get
(
url
):
host
=
domain
.
switch_domain
(
country
)
full_url
=
host
+
url
page
.
get
(
full_url
,
timeout
=
3
)
def
export_list_read_data
():
new_file_name
=
'new_Payments.xlsx'
if
os
.
path
.
isfile
(
new_file_name
):
...
...
@@ -34,13 +40,13 @@ def export_list_read_data():
file_name
=
'Payments.xlsx'
if
not
os
.
path
.
isfile
(
file_name
):
#
raise FileNotFoundError(f"{file_name},文件不存在")
raise
FileNotFoundError
(
f
"{file_name},文件不存在"
)
pass
page
.
get
(
f
"https://vendorcentral.amazon.com/hz/vendor/members/remittance/home"
,
timeout
=
3
)
page
.
ele
(
"#remittance-home-select-all"
,
timeout
=
2
)
.
click
()
page
.
ele
(
"#remittance-home-export-link"
,
timeout
=
2
)
.
click
.
to_download
()
file
.
wait_for_downloads
(
file_name
)
# page_get(f"hz/vendor/members/remittance/home"
)
#
page.ele("#remittance-home-select-all", timeout=2).click()
#
page.ele("#remittance-home-export-link", timeout=2).click.to_download()
#
file.wait_for_downloads(file_name)
all_df
=
pd
.
read_excel
(
file_name
,
header
=
None
)
...
...
@@ -70,13 +76,13 @@ def export_list_read_data():
def
export_details_read_data
(
invoice_number
):
params
=
{
"invoiceNumber"
:
invoice_number
,
"payeeCode"
:
"
VECET
"
,
"payeeCode"
:
"
E8PFB
"
,
"activeTab"
:
"lineItems"
,
}
# 将字典转换为 URL 查询参数
query_string
=
urllib
.
parse
.
urlencode
(
params
)
full_url
=
f
"h
ttps://vendorcentral.amazon.com/h
z/vendor/members/inv-mgmt/invoice-details?"
+
query_string
page
.
get
(
full_url
,
timeout
=
3
)
full_url
=
f
"hz/vendor/members/inv-mgmt/invoice-details?"
+
query_string
page
_get
(
full_url
)
# 读取详情内容
file_name
=
f
"invoices
\\
{invoice_number}.csv"
...
...
@@ -108,7 +114,7 @@ def get_po_code(index, po_id) -> dict:
"po_id"
:
po_id
}
page
.
get
(
f
"https://vendorcentral.amazon.com/po/vendor/members/po-mgmt/order?poId={po_id}"
,
timeout
=
3
)
page
_get
(
f
"po/vendor/members/po-mgmt/order?poId={po_id}"
)
po_table
=
page
.
ele
(
"#po-header"
,
timeout
=
5
)
.
html
# 使用 lxml 解析 HTML
...
...
@@ -122,7 +128,7 @@ def get_po_code(index, po_id) -> dict:
if
match
:
result
[
"payment_terms"
]
=
match
.
group
(
1
)[:
-
1
]
# 去掉%
else
:
result
[
"payment_terms"
]
=
None
result
[
"payment_terms"
]
=
0
return
result
...
...
@@ -168,12 +174,12 @@ def price_extract_data(html_content):
def
click_get_price_data
():
try
:
# 获取 Amounts 表格html
page_html
=
page
.
ele
(
".a-box-inner"
,
timeout
=
5
)
.
html
page_html
=
page
.
ele
(
".a-box-inner"
,
timeout
=
3
)
.
html
# 使用 lxml 解析 HTML
tree
=
etree
.
HTML
(
page_html
)
#
使用 XPath 查找第三个 span class="a-color-base invoice-property-field"
#
提取第二个 class="a-column a-span4" 下的第三个 class="a-row invoice-property-field-row" 下的 span 的值
price_variance_amount
=
tree
.
xpath
(
'
//span[contains(text(),"Price variance amount (price claim)")]/../..
/div[@class="a-column a-span6 a-span-last"]/span/text()'
)
'
(//div[@class="a-column a-span4"])[2]//div[@class="a-row invoice-property-field-row"][3]/
/div[@class="a-column a-span6 a-span-last"]/span/text()'
)
# 检查内容是否有效
if
price_variance_amount
and
price_variance_amount
[
0
]
.
strip
()
!=
"-"
:
page
.
ele
(
"#pd"
,
timeout
=
5
)
.
click
()
...
...
@@ -221,8 +227,11 @@ def handle_data(detail_datum, vendor, deduction_points):
if
detail_datum
.
get
(
'Shortage quantity'
,
-
1
)
==
0
:
is_finished
=
"是"
# 计算扣除后的金额
amount_after_deduction
=
amount
-
(
amount
*
(
deduction_points
/
100
))
amount_after_deduction
=
amount
if
deduction_points
>
0
:
# 计算扣除后的金额
amount_after_deduction
=
amount
-
(
amount
*
(
deduction_points
/
100
))
# 复制原始行数据,避免直接修改
record
=
detail_datum
.
copy
()
record
[
"IsFinished"
]
=
is_finished
...
...
@@ -235,8 +244,8 @@ def handle_data(detail_datum, vendor, deduction_points):
def
main
():
list_data
=
export_list_read_data
()
# list_data = list_data[62:]
print
(
f
"共计:{len(list_data)} 订单"
)
all_normal_pay_data
=
[]
all_price_pay_data
=
[]
i
=
0
...
...
@@ -247,8 +256,7 @@ def main():
invoice_number
=
invoice_number
[:
8
]
# 获取当前订单的Payee和优惠比例
vendor_payment_terms
=
get_po_code
(
i
,
invoice_number
)
page
.
wait
(
2
)
vendor_payment_terms
=
get_po_code
(
i
,
invoice_number
)
print
(
vendor_payment_terms
)
vendor
=
vendor_payment_terms
[
'vendor'
]
...
...
@@ -256,7 +264,6 @@ def main():
# 下载excel文件并读取数据
detail_data
=
export_details_read_data
(
invoice_number
)
page
.
wait
(
2
)
# 获取争议数据
all_price_data
=
click_get_price_data
()
...
...
@@ -297,6 +304,12 @@ def main():
if
__name__
==
'__main__'
:
try
:
country
=
helper
.
get_input_with_default
(
"国家"
,
"usa"
)
if
country
is
None
:
raise
Exception
(
"请选择国家"
)
main
()
except
KeyboardInterrupt
:
pass
except
Exception
as
e
:
print
(
e
)
returns.py
View file @
fe4c52b5
...
...
@@ -6,10 +6,9 @@ import pandas as pd
from
DrissionPage
import
ChromiumPage
from
DrissionPage.errors
import
ElementNotFoundError
from
helper
import
helper
,
excel
,
file
from
helper
import
helper
,
excel
,
file
,
domain
email
=
None
password
=
None
country
=
None
page
=
ChromiumPage
()
page
.
set
.
load_mode
.
eager
()
...
...
@@ -23,6 +22,12 @@ helper.make_dir(download_path)
page
.
set
.
download_path
(
download_path
)
def
page_get
(
url
):
host
=
domain
.
switch_domain
(
country
)
full_url
=
host
+
url
page
.
get
(
full_url
,
timeout
=
3
)
def
sku_relations
():
relations_dict
=
{}
# 读取ASIN和sku映射关系
...
...
@@ -41,12 +46,12 @@ def sku_relations():
def
export_list_read_data
():
file_name
=
"Return_Summary.xls"
if
not
os
.
path
.
isfile
(
file_name
):
#
raise FileNotFoundError(f"{file_name},文件不存在")
raise
FileNotFoundError
(
f
"{file_name},文件不存在"
)
# 访问网页
page
.
get
(
"https://vendorcentral.amazon.com/hz/vendor/members/returns?ref_=vc_xx_subNav"
,
timeout
=
3
)
# 导出退货单
page
.
ele
(
"#file-download-button"
)
.
click
.
to_download
()
file
.
wait_for_downloads
(
file_name
)
# page_get("hz/vendor/members/returns?ref_=vc_xx_subNav"
)
#
#
导出退货单
#
page.ele("#file-download-button").click.to_download()
#
file.wait_for_downloads(file_name)
return
pd
.
read_excel
(
file_name
,
engine
=
'xlrd'
)
...
...
@@ -57,7 +62,7 @@ def export_item_read_data(return_id):
while
True
:
try
:
# 打开退回详情下载明细
page
.
get
(
f
"https://vendorcentral.amazon.com/katalmonsapp/vendor/members/returns/{return_id}"
,
timeout
=
3
)
page
_get
(
f
"katalmonsapp/vendor/members/returns/{return_id}"
)
page
.
ele
(
"#file-download-button"
)
.
click
.
to_download
(
rename
=
file_name
)
file
.
wait_for_downloads
(
file_name
)
break
...
...
@@ -72,10 +77,11 @@ def export_item_read_data(return_id):
def
main
():
# 读取sku映射关系
relations_dict
=
sku_relations
()
# 下载并读取list数据
list_data
=
export_list_read_data
()
print
(
f
"共计:{len(list_data)} 订单"
)
new_list_data
=
[]
i
=
0
for
_
,
data
in
list_data
.
iterrows
():
...
...
@@ -113,6 +119,12 @@ def main():
if
__name__
==
'__main__'
:
try
:
country
=
helper
.
get_input_with_default
(
"国家"
,
"usa"
)
if
country
is
None
:
raise
Exception
(
"请选择国家"
)
main
()
except
KeyboardInterrupt
:
pass
except
Exception
as
e
:
print
(
e
)
\ No newline at end of file
print
(
e
)
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