Add resilience to missing authorChannelId in main.cpp

This commit is contained in:
Benjamin Loison 2022-12-22 05:41:38 +01:00
parent 95a9421ad0
commit 6685c13706

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