add:添加翻译间隔。
This commit is contained in:
parent
a793406ab7
commit
5f7d6a1f80
@ -2,3 +2,4 @@
|
||||
BaseURL = https://fanyi-api.baidu.com/api/trans/vip/translate?
|
||||
AppID =
|
||||
SecretID =
|
||||
Interval = 200
|
@ -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;
|
||||
}
|
||||
|
1
handle.h
1
handle.h
@ -47,6 +47,7 @@ struct ConfigInfo {
|
||||
std::string baseUrl;
|
||||
std::string appID;
|
||||
std::string secretID;
|
||||
std::string interval{"1000"};
|
||||
};
|
||||
|
||||
class CConfig
|
||||
|
7
main.cpp
7
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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user