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
e61bb4a6
Commit
e61bb4a6
authored
Oct 18, 2024
by
邱阿朋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
回款数据
parent
7690d798
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
203 additions
and
39 deletions
+203
-39
excel.py
helper/excel.py
+27
-0
file.py
helper/file.py
+5
-5
invoices.py
invoices.py
+171
-34
No files found.
helper/excel.py
View file @
e61bb4a6
# coding: utf-8
import
re
import
pandas
as
pd
import
xlrd
from
openpyxl.reader.excel
import
load_workbook
...
...
@@ -46,3 +48,28 @@ def save_xls(data, output_file, sheet_name='Sheet1', adjusted=True):
ws
.
column_dimensions
[
column_letter
]
.
width
=
adjusted_width
wb
.
save
(
output_file
)
def
remove_last_comma
(
csv_file
,
skip_rows
=
2
):
# 创建一个空列表用于存储处理后的行
cleaned_lines
=
[]
# 读取原始 CSV 文件并处理行末的逗号
with
open
(
csv_file
,
'r'
,
encoding
=
'utf-8'
)
as
file
:
# 跳过指定数量的行
for
_
in
range
(
skip_rows
):
next
(
file
)
# 跳过每一行
for
line
in
file
:
# 使用正则表达式替换 空格 + 数字 + 引号
cleaned_line
=
re
.
sub
(
r'(\s\d+)"'
,
r'\1 '
,
line
)
# 去掉空格 + 数字后面的引号
# 使用正则表达式替换每个逗号前的空格为引号
cleaned_line
=
re
.
sub
(
r'\s+,\s*"'
,
r'", "'
,
cleaned_line
)
# 去掉末尾的逗号和换行符
cleaned_line
=
cleaned_line
.
rstrip
(
',
\n
'
)
# 不添加换行符,待会写入时统一处理
cleaned_lines
.
append
(
cleaned_line
)
# 将处理后的数据写入同一个文件
with
open
(
csv_file
,
'w'
,
encoding
=
'utf-8'
,
newline
=
''
)
as
cleaned_file
:
cleaned_file
.
write
(
'
\n
'
.
join
(
cleaned_lines
)
+
'
\n
'
)
# 使用 join 处理换行符
helper/file.py
View file @
e61bb4a6
...
...
@@ -3,16 +3,16 @@ import os
import
time
def
wait_for_downloads
(
download_dir
,
timeout
=
60
):
def
wait_for_downloads
(
file_name
,
timeout
=
60
):
"""
监控下载
目录
,等待新文件下载完成。
:param
download_dir
: 文件下载目录
监控下载
文件
,等待新文件下载完成。
:param
file_name
: 文件下载目录
:param timeout: 超时时间,单位:秒
"""
end_time
=
time
.
time
()
+
timeout
while
time
.
time
()
<
end_time
:
files
=
os
.
listdir
(
download_dir
)
if
files
:
# 如果文件夹内有文件
files
=
os
.
path
.
isfile
(
file_name
)
if
files
:
return
True
time
.
sleep
(
1
)
return
False
...
...
invoices.py
View file @
e61bb4a6
This diff is collapsed.
Click to expand it.
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