Add resilience to missing authorChannelId in main.cpp

This commit is contained in:
Benjamin Loison 2022-12-22 05:41:38 +01:00
parent 2ffc1d0e5d
commit eaae954e1b
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -19,7 +19,6 @@ size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp);
#define PRINT(x) toPrint << x; print(&toPrint);
ostringstream toPrint;
// TODO: change to `set`s
set<string> channelsToTreat,
channelsAlreadyTreated;
unsigned int commentsCount = 0;
@ -109,19 +108,15 @@ int main()
void treatComment(json comment)
{
PRINT("id: " << comment["id"])
json snippet = comment["snippet"];
PRINT("snippet: " << snippet)
if(snippet.contains("videoId"))
PRINT("videoId: " << snippet["videoId"])
json authorChannelId = snippet["authorChannelId"];
PRINT("authorChannelId: " << authorChannelId)
string channelId = comment["snippet"]["authorChannelId"]["value"];
PRINT("channelId: " << channelId)
commentsCount++;
//PRINT(channelId)
// The `else` case can happen (cf `95a9421ad0469a09335afeddb2983e31dc00bc36`).
if(snippet.contains("authorChannelId"))
{
string channelId = snippet["authorChannelId"]["value"];
if(find(channelsAlreadyTreated.begin(), channelsAlreadyTreated.end(), channelId) == channelsAlreadyTreated.end())
channelsToTreat.insert(channelId);
}
commentsCount++;
}
vector<string> getFileContent(string filePath)