#include #include #include #include #include #include #include std::string yearstr(int year) { return year==-1? "Unknown": std::to_string(year); } int main() { char filename[64]; snprintf(filename, sizeof filename, "out.csv"); std::ofstream out_file1; out_file1.open(filename); out_file1<<"id, Caption/title, production start year, end year, Description, Source, image_filename, collection name, museum name, linceses\n"; for (auto i = 0; i<4; i++) { char in_file_i[64]; snprintf(in_file_i, sizeof in_file_i, "data_%d.json", i); // Open the file FILE* fp = fopen(in_file_i, "rb"); // Check if the file was opened successfully if (!fp) { std::cerr << "Error: unable to open file" << std::endl; return -1; } // Read the file char readBuffer[192000]; rapidjson::FileReadStream is(fp, readBuffer, sizeof(readBuffer)); // Parse the JSON document rapidjson::Document doc; doc.ParseStream(is); // Check if the document is valid if (doc.HasParseError()) { std::cerr << "Error: failed to parse JSON document" << std::endl; fclose(fp); return 1; } // Close the file fclose(fp); if (doc.HasMember("response") && doc["response"].IsObject()) { const rapidjson::Value& response = doc["response"]; if (response.HasMember("docs") && response["docs"].IsArray()) { std::cout<<"yes, response is an array"<?dimension= // as per documentation available at http://api.dimu.org/doc/public_api.html char imglink[128]; snprintf(imglink, sizeof imglink, "https://mm.dimu.org/image/%s", mediaid.c_str()); char descfilename[64]; snprintf(descfilename, sizeof descfilename, "%s.txt", article_id.c_str()); std::string description = ""; if (article.HasMember("artifact.ingress.description")) { const rapidjson::Value& descv = article["artifact.ingress.description"]; if (descv.IsString()) { description = descv.GetString(); std::replace( description.begin(), description.end(), ',', ':'); std::replace( description.begin(), description.end(), '\n', ' '); std::ofstream desc_file; desc_file.open(descfilename); desc_file<