Add progression save and use spaces instead of tabs
This commit is contained in:
parent
934954092a
commit
36f1fb9e83
52
main.cpp
52
main.cpp
@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <sys/stat.h>
|
||||
#include <curl/curl.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
using namespace std;
|
||||
@ -8,10 +9,13 @@ using json = nlohmann::json;
|
||||
|
||||
vector<string> getFileContent(string filePath);
|
||||
json getJson(string url);
|
||||
void print(ostringstream* toPrint),
|
||||
void createDirectory(string path),
|
||||
print(ostringstream* toPrint),
|
||||
treatComment(json comment);
|
||||
string getHttps(string url);
|
||||
size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp);
|
||||
bool doesFileExist(string filePath),
|
||||
writeFile(string filePath, string option, string toWrite);
|
||||
|
||||
#define API_KEY "AIzaSy..."
|
||||
|
||||
@ -19,16 +23,26 @@ size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp);
|
||||
#define PRINT(x) toPrint << x; print(&toPrint);
|
||||
ostringstream toPrint;
|
||||
|
||||
set<string> channelsToTreat,
|
||||
channelsAlreadyTreated;
|
||||
set<string> channelsAlreadyTreated,
|
||||
channelsToTreat;
|
||||
unsigned int commentsCount = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
vector<string> channelsToTreatVec = getFileContent("channelsToTreat.txt");
|
||||
string channelsToTreatFilePath = "channelsToTreat.txt";
|
||||
vector<string> channelsToTreatVec = getFileContent(channelsToTreatFilePath);
|
||||
channelsToTreat = set(channelsToTreatVec.begin(), channelsToTreatVec.end());
|
||||
|
||||
string channelsDirectory = "channels/";
|
||||
createDirectory(channelsDirectory);
|
||||
|
||||
for(const auto& entry : filesystem::directory_iterator(channelsDirectory))
|
||||
{
|
||||
channelsAlreadyTreated.insert(entry.path().filename());
|
||||
}
|
||||
|
||||
PRINT(channelsToTreat.size() << " channel(s) to treat")
|
||||
PRINT(channelsAlreadyTreated.size() << " channel(s) already treated")
|
||||
|
||||
while(!channelsToTreat.empty())
|
||||
{
|
||||
@ -99,8 +113,15 @@ int main()
|
||||
|
||||
PRINT(commentsCount)
|
||||
commentsCount = 0;
|
||||
|
||||
channelsToTreat.erase(channelToTreat);
|
||||
channelsAlreadyTreated.insert(channelToTreat);
|
||||
|
||||
string channelToTreatDirectory = channelsDirectory + channelToTreat + "/";
|
||||
createDirectory(channelToTreatDirectory);
|
||||
|
||||
string toWrite = (doesFileExist(channelsToTreatFilePath) ? "\n" : "") + channelToTreat;
|
||||
writeFile(channelsToTreatFilePath, "a", toWrite);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -119,6 +140,29 @@ void treatComment(json comment)
|
||||
commentsCount++;
|
||||
}
|
||||
|
||||
bool writeFile(string filePath, string option, string toWrite)
|
||||
{
|
||||
FILE* file = fopen(filePath.c_str(), option.c_str());
|
||||
if(file != NULL)
|
||||
{
|
||||
fputs(toWrite.c_str(), file);
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool doesFileExist(string filePath)
|
||||
{
|
||||
struct stat buffer;
|
||||
return stat(filePath.c_str(), &buffer) == 0;
|
||||
}
|
||||
|
||||
void createDirectory(string path)
|
||||
{
|
||||
mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
}
|
||||
|
||||
string getDate()
|
||||
{
|
||||
auto t = time(nullptr);
|
||||
|
Loading…
Reference in New Issue
Block a user