2023-03-08 13:18:12 +00:00
|
|
|
#include <fstream>
|
2023-04-04 12:25:15 +00:00
|
|
|
#include <sstream>
|
2023-03-08 13:18:12 +00:00
|
|
|
|
2023-03-26 07:58:15 +00:00
|
|
|
#include <cstdio>
|
2023-04-04 12:25:15 +00:00
|
|
|
#include <cstdlib>
|
2023-03-08 13:18:12 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2023-03-26 07:58:15 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-03-08 13:18:12 +00:00
|
|
|
#include <curlpp/Easy.hpp>
|
|
|
|
#include <curlpp/Exception.hpp>
|
2023-04-04 12:25:15 +00:00
|
|
|
#include <curlpp/Options.hpp>
|
|
|
|
#include <curlpp/cURLpp.hpp>
|
2023-03-08 13:18:12 +00:00
|
|
|
|
|
|
|
#define DEBUG_LEVEL -1
|
|
|
|
|
2023-04-04 12:25:15 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2023-03-26 07:58:15 +00:00
|
|
|
std::string exbid, apikey;
|
2023-04-04 12:25:15 +00:00
|
|
|
if (argc != 7) {
|
|
|
|
std::cout << "Usage: " << argv[0]
|
|
|
|
<< " -e <exhibition id> -k <api key> -e <number of records>"
|
|
|
|
<< std::endl;
|
2023-03-08 13:18:12 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2023-03-26 07:58:15 +00:00
|
|
|
int c;
|
2023-03-26 08:26:58 +00:00
|
|
|
int numrec = 0;
|
2023-04-04 12:25:15 +00:00
|
|
|
while ((c = getopt(argc, argv, "e:k:n:")) != -1)
|
|
|
|
switch (c) {
|
|
|
|
case 'e':
|
|
|
|
exbid = optarg;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
apikey = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
numrec = atoi(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::cout << numrec << " records to fetch\n";
|
2023-03-26 08:26:58 +00:00
|
|
|
int numfetches = (numrec / 100) + 1;
|
2023-03-08 13:18:12 +00:00
|
|
|
char url[256], outfilename[64];
|
2023-04-04 12:25:15 +00:00
|
|
|
for (int i = 0; i < numfetches; i++) {
|
|
|
|
snprintf(url, sizeof url,
|
|
|
|
"https://api.dimu.org/api/solr/"
|
|
|
|
"select?q=Kosta&wt=json&fq=(artifact.exhibitionUids:\"%s\")&start="
|
|
|
|
"%d&rows=100&api.key=%s",
|
|
|
|
exbid.c_str(), i * 100, apikey.c_str());
|
2023-03-26 07:58:15 +00:00
|
|
|
|
2023-04-04 12:25:15 +00:00
|
|
|
std::cout << url << "\n";
|
2023-03-26 07:58:15 +00:00
|
|
|
|
2023-03-08 13:18:12 +00:00
|
|
|
snprintf(outfilename, sizeof outfilename, "data_%d.json", i);
|
|
|
|
|
2023-04-04 12:25:15 +00:00
|
|
|
if (DEBUG_LEVEL > 0) {
|
|
|
|
std::cout << "url to fetch is " << std::endl << url << std::endl;
|
|
|
|
std::cout << "writing output to " << outfilename << std::endl;
|
|
|
|
}
|
2023-03-08 13:18:12 +00:00
|
|
|
|
2023-04-04 12:25:15 +00:00
|
|
|
try {
|
|
|
|
curlpp::Cleanup cleaner;
|
|
|
|
curlpp::Easy request1;
|
2023-03-08 13:18:12 +00:00
|
|
|
|
2023-04-04 12:25:15 +00:00
|
|
|
// Setting the URL to retrive.
|
|
|
|
request1.setOpt(new curlpp::options::Url(url));
|
2023-03-08 13:18:12 +00:00
|
|
|
|
2023-04-04 12:25:15 +00:00
|
|
|
if (DEBUG_LEVEL > 0)
|
|
|
|
std::cout << request1 << std::endl;
|
|
|
|
|
|
|
|
std::ofstream outfile;
|
|
|
|
outfile.open(outfilename);
|
|
|
|
outfile << curlpp::options::Url(url) << std::endl;
|
|
|
|
outfile.close();
|
|
|
|
} catch (curlpp::LogicError &e) {
|
|
|
|
if (DEBUG_LEVEL > 0)
|
|
|
|
std::cout << e.what() << std::endl;
|
|
|
|
} catch (curlpp::RuntimeError &e) {
|
|
|
|
if (DEBUG_LEVEL > 0)
|
|
|
|
std::cout << e.what() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2023-03-08 13:18:12 +00:00
|
|
|
}
|