From 5f7d6a1f805444462ba897ae5b0fed90df817cb0 Mon Sep 17 00:00:00 2001
From: taynpg <taynpg@163.com>
Date: Tue, 4 Mar 2025 11:19:09 +0800
Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E7=BF=BB?=
 =?UTF-8?q?=E8=AF=91=E9=97=B4=E9=9A=94=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 fanyi.ini  | 3 ++-
 handle.cpp | 8 ++++++++
 handle.h   | 1 +
 main.cpp   | 7 ++++++-
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/fanyi.ini b/fanyi.ini
index dcb3cff..171e92e 100644
--- a/fanyi.ini
+++ b/fanyi.ini
@@ -1,4 +1,5 @@
 [Config]
 BaseURL = https://fanyi-api.baidu.com/api/trans/vip/translate?
 AppID = 
-SecretID = 
\ No newline at end of file
+SecretID = 
+Interval = 200
\ No newline at end of file
diff --git a/handle.cpp b/handle.cpp
index 8c587ba..f59405e 100644
--- a/handle.cpp
+++ b/handle.cpp
@@ -145,15 +145,23 @@ bool CConfig::parse_config(ConfigInfo& config, const std::string& config_path)
         return false;
     }
     config.baseUrl = ini_handle.GetValue("Config", "BaseURL");
+
     if (!ini_handle.KeyExists("Config", "AppID")) {
         std::cerr << "Not Key Found Config/AppID in fanyi.ini" << std::endl;
         return false;
     }
     config.appID = ini_handle.GetValue("Config", "AppID");
+
     if (!ini_handle.KeyExists("Config", "SecretID")) {
         std::cerr << "Not Key Found Config/SecretID in fanyi.ini" << std::endl;
         return false;
     }
     config.secretID = ini_handle.GetValue("Config", "SecretID");
+
+    if (!ini_handle.KeyExists("Config", "Interval")) {
+        std::cerr << "Not Key Found Config/Interval in fanyi.ini" << std::endl;
+        return false;
+    }
+    config.interval = ini_handle.GetValue("Config", "Interval");
     return true;
 }
diff --git a/handle.h b/handle.h
index ddcd5b4..0f70a40 100644
--- a/handle.h
+++ b/handle.h
@@ -47,6 +47,7 @@ struct ConfigInfo {
     std::string baseUrl;
     std::string appID;
     std::string secretID;
+    std::string interval{"1000"};
 };
 
 class CConfig
diff --git a/main.cpp b/main.cpp
index 9886310..9ed735e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -6,6 +6,7 @@
 #include <thread>
 #include <xlnt/xlnt.hpp>
 #include <unordered_map>
+#include <cctype>
 
 // #include <filesystem>
 using json = nlohmann::json;
@@ -55,6 +56,10 @@ int main(int argc, char* argv[])
     std::cout << "BaseURL:" << base_info.baseUrl << "\n";
     std::cout << "AppID:" << base_info.appID << "\n";
     std::cout << "SecretID:" << base_info.secretID << std::endl;
+    std::cout << "Interval:" << base_info.interval << std::endl;
+
+    int interval = std::stoi(base_info.interval);
+    interval = interval < 100 ? 100 : interval;
 
     auto https = std::make_shared<CHttpsHandle>();
     auto trans_tool = std::make_shared<CTransTool>();
@@ -98,7 +103,7 @@ int main(int argc, char* argv[])
             word_map[line] = ret;
         }
         std::cout << "翻译:" << line << ", 结果:" << ret << std::endl;
-        std::this_thread::sleep_for(std::chrono::milliseconds(200));
+        std::this_thread::sleep_for(std::chrono::milliseconds(interval));
     }
     in.close();