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);
|
#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)
|
||||||
|
Loading…
Reference in New Issue
Block a user