Skip download and import directly if file for the date already exists

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Niko 2026-05-05 16:06:48 +08:00
parent c7a4683340
commit 9174a4cc40

View File

@ -81,6 +81,16 @@ public class EtsScraper {
String dateStrFileName = targetDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")); String dateStrFileName = targetDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
Path downloadPath = Path.of("downloads").toAbsolutePath().normalize();
Path savedFile = downloadPath.resolve("三联单列表_" + dateStrFileName + ".xls");
if (java.nio.file.Files.exists(savedFile) && java.nio.file.Files.size(savedFile) > 0) {
System.out.println("[+] File already exists: " + savedFile);
System.out.println("[+] File size: " + java.nio.file.Files.size(savedFile) + " bytes");
autoImportBill(savedFile, proxyHost, proxyUser, proxyPass);
return;
}
try { try {
createDirectories(SCREENSHOT_DIR); createDirectories(SCREENSHOT_DIR);
} catch (Exception e) { } catch (Exception e) {
@ -195,8 +205,6 @@ public class EtsScraper {
if (page.locator("#Export_ThreeBillList_Button").count() > 0) { if (page.locator("#Export_ThreeBillList_Button").count() > 0) {
System.out.println("[*] Clicking export button..."); System.out.println("[*] Clicking export button...");
// 设置下载目录 // 设置下载目录
Path downloadPath = Path.of("downloads").toAbsolutePath().normalize();
java.nio.file.Files.createDirectories(downloadPath);
// 点击主导出按钮打开对话框再用 JS click 触发对话框内导出按钮 // 点击主导出按钮打开对话框再用 JS click 触发对话框内导出按钮
Download dl = page.waitForDownload( Download dl = page.waitForDownload(
new Page.WaitForDownloadOptions().setTimeout(300000), new Page.WaitForDownloadOptions().setTimeout(300000),
@ -207,7 +215,6 @@ public class EtsScraper {
page.evaluate("document.querySelectorAll('button').forEach(b => { if (b.textContent.trim() === '导出') b.click(); })"); page.evaluate("document.querySelectorAll('button').forEach(b => { if (b.textContent.trim() === '导出') b.click(); })");
}); });
System.out.println("[*] Waiting for download to complete..."); System.out.println("[*] Waiting for download to complete...");
Path savedFile = downloadPath.resolve("三联单列表_" + dateStrFileName + ".xls");
dl.saveAs(savedFile); dl.saveAs(savedFile);
System.out.println("[+] Download saved to: " + savedFile); System.out.println("[+] Download saved to: " + savedFile);
if (java.nio.file.Files.size(savedFile) == 0) { if (java.nio.file.Files.size(savedFile) == 0) {