Command line argument parsing with getopt - for fetcher
This commit is contained in:
parent
dc989c1892
commit
46782d89e4
24
fetcher.cc
24
fetcher.cc
|
@ -2,8 +2,11 @@
|
|||
#include <fstream>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <curlpp/Easy.hpp>
|
||||
#include <curlpp/Options.hpp>
|
||||
|
@ -13,13 +16,30 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc !=3 ) {
|
||||
std::string exbid, apikey;
|
||||
if (argc !=5 ) {
|
||||
std::cout<<"Please run as "<<argv[0] <<" <exhibition id> <api key>"<<std::endl;
|
||||
exit(0);
|
||||
}
|
||||
int c;
|
||||
while ((c = getopt (argc, argv, "e:k:")) != -1)
|
||||
switch(c)
|
||||
{
|
||||
case 'e':
|
||||
exbid = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
apikey = optarg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
char url[256], outfilename[64];
|
||||
for (int i = 0; i<4; 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", argv[1], i*100, argv[2]);
|
||||
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());
|
||||
|
||||
std::cout<<url<<"\n";
|
||||
|
||||
snprintf(outfilename, sizeof outfilename, "data_%d.json", i);
|
||||
|
||||
/*if (DEBUG_LEVEL > 0) */std::cout<<"url to fetch is "<<std::endl<<url<<std::endl;
|
||||
|
|
Loading…
Reference in New Issue