Add resilience to missing authorChannelId
in main.cpp
This commit is contained in:
parent
2ffc1d0e5d
commit
eaae954e1b
19
main.cpp
19
main.cpp
@ -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)
|
||||
// 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++;
|
||||
//PRINT(channelId)
|
||||
if(find(channelsAlreadyTreated.begin(), channelsAlreadyTreated.end(), channelId) == channelsAlreadyTreated.end())
|
||||
channelsToTreat.insert(channelId);
|
||||
}
|
||||
|
||||
vector<string> getFileContent(string filePath)
|
||||
|
Loading…
Reference in New Issue
Block a user