#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <ctime>
#ifdef linux
#include <unistd.h>
#endif
#if defined(_WINDOWS) || defined(WIN32)
#include <windows.h>
#endif
using namespace std;
int main(int argc, char const *argv[])
{
#if defined(_WINDOWS) || defined(WIN32)
system("chcp 65001");
system("cls");
#endif
#ifdef linux
system("clear");
#endif
ifstream file;
file.open("./test.txt", ios::in);
string buff, temp = "curl ", result;
int order = 0;
long long wheel = 1;
vector<string> page;
while (getline(file, buff))
{
#if defined(_WINDOWS) || defined(WIN32)
result = temp + buff + " >nul 2>nul";
#endif
#ifdef linux
result = temp + buff + " >/dev/null 2>/dev/null";
#endif
page.push_back(result);
}
file.close();
int looptime = 0, onlytime = 0, randtask = 0;
vector<int> randtasktable;
cout << "正在准备执行第" << wheel << "轮" << endl;
while (true)
{
randtasktable.clear();
srand(time(NULL));
while (true)
{
randtask = rand() % page.size();
if (std::find(randtasktable.begin(), randtasktable.end(), randtask) == randtasktable.end())
{
randtasktable.push_back(randtask);
}
if (randtasktable.size() >= page.size() * 0.7)
{
break;
}
}
looptime = rand() % 3 + 3;
cout << "正在执行第" << wheel << "轮" << endl;
for (auto &i : randtasktable)
{
onlytime = rand() % 3 + 1;
std::cout << "正在执行第" << ++order << "个" << std::endl;
system(page[i].c_str());
#if defined(_WINDOWS) || defined(WIN32)
Sleep(onlytime * 1000);
#endif
#ifdef linux
sleep(onlytime);
#endif
}
order = 0;
#if defined(_WINDOWS) || defined(WIN32)
system("cls");
#endif
#ifdef linux
system("clear");
#endif
cout << "正在准备执行第" << ++wheel << "轮" << endl;
#if defined(_WINDOWS) || defined(WIN32)
Sleep(1000 * 60 * looptime);
#endif
#ifdef linux
sleep(60 * looptime);
#endif
}
return 0;
}