Commit e61bb4a6 authored by 邱阿朋's avatar 邱阿朋

回款数据

parent 7690d798
# 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 处理换行符
......@@ -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
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment