forked from gridcoin-community/ScraperProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.h
885 lines (663 loc) · 22.9 KB
/
scraper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
#ifndef SCRAPER_H
#define SCRAPER_H
#include <string>
#include <vector>
#include <cmath>
#include <zlib.h>
#include <iostream>
#include <curl/curl.h>
#include <inttypes.h>
#include <algorithm>
#include <cctype>
#include <vector>
#include <boost/exception/exception.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/filesystem.hpp>
//#include <expat.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <chrono>
#include <thread>
#include <sstream>
#include <jsoncpp/json/json.h>
/*********************
* Scraper Namepsace *
*********************/
namespace fs = boost::filesystem;
namespace boostio = boost::iostreams;
/*********************
* Scraper ENUMS *
*********************/
enum logattribute {
INFO,
WARNING,
ERROR,
CRITICAL
};
/*********************
* Functions *
*********************/
void _log(logattribute eType, const std::string& sCall, const std::string& sMessage);
void _nntester(logattribute eType, const std::string& sCall, const std::string& sMessage);
std::vector<std::string> split(const std::string& s, const std::string& delim);
/*********************
* Global Vars *
*********************/
bool fDebug = true;
std::vector<std::pair<std::string, std::string>> vwhitelist;
std::vector<std::pair<std::string, std::string>> vuserpass;
std::vector<std::pair<std::string, int64_t>> vprojectteamids;
std::vector<std::string> vauthenicationetags;
std::string rpcauth = "testnet:testme";
std::string rpcip = "http://127.0.0.1:9331/";
int64_t ndownloadsize = 0;
int64_t nuploadsize = 0;
/*********************
* Scraper *
*********************/
class scraper
{
public:
scraper();
};
/********************
* Scraper Curl *
********************/
class statscurl
{
private:
CURL* curl;
std::string buffer;
std::string buffertwo;
std::string header;
long http_code;
CURLcode res;
static size_t writeheader(void* ptr, size_t size, size_t nmemb, void* userp)
{
((std::string*)userp)->append((char*)ptr, size * nmemb);
return size * nmemb;
}
static size_t writetofile(void* ptr, size_t size, size_t nmemb, FILE* fp)
{
return fwrite(ptr, size, nmemb, fp);
}
static size_t writestring(const char* in, size_t size, size_t nmemb, std::string* out)
{
const std::size_t totalBytes(size * nmemb);
out->append(in, totalBytes);
return totalBytes;
}
public:
statscurl()
: curl(curl_easy_init())
{
}
~statscurl()
{
if (curl)
{
curl_easy_cleanup(curl);
curl_global_cleanup();
}
}
bool httpcode(const std::string& response, const std::string& url)
{
// Check code to make sure we have success as even a response is considered an OK
// We check only on head requests since they give us the information we need
// Codes we send back true and wait for other HTTP/ code is 301, 302, 307 and 308 since these are follows
if (response.empty())
{
_log(ERROR, "httpcode", "Server returned an empty HTTP code <prjurl=" + url+ ">");
return false;
}
if (response == "200")
return true;
else if (response == "400")
_log(ERROR, "httpcode", "Server returned a http code of Bad Request <prjurl=" + url + ", code=" + response + ">");
else if (response == "401")
_log(ERROR, "httpcode", "Server returned a http code of Unauthroized <prjurl=" + url + ", code=" + response + ">");
else if (response == "403")
_log(ERROR, "httpcode", "Server returned a http code of Forbidden <prjurl=" + url + ", code=" + response + ">");
else if (response == "404")
_log(ERROR, "httpcode", "Server returned a http code of Not Found <prjurl=" + url + ", code=" + response + ">");
else if (response == "301")
return true;
else if (response == "302")
return true;
else if (response == "307")
return true;
else if (response == "308")
return true;
else
_log(ERROR, "httpcode", "Server returned a http code <prjurl=" + url + ", code=" + response + ">");
return false;
}
bool rpccall(const std::string& type, const std::string& params, std::string& reply)
{
std::string strdata;
if (params.empty())
strdata = "{\"jsonrpc\" : \"1.0\", \"id\" : \"" + type + "\", \"method\" : \"" + type + "\", \"params\" : []}";
else
strdata = "{\"jsonrpc\" : \"1.0\", \"id\" : \"" + type + "\", \"method\" : \"" + type + "\", \"params\" : [\"project\"]}";
const char* data = strdata.c_str();
struct curl_slist* rpcheaders = NULL;
rpcheaders = curl_slist_append(rpcheaders, "content-type: text/plain;");
curl_easy_setopt(curl, CURLOPT_URL, rpcip.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writestring);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffertwo);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, rpcheaders);
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);
curl_easy_setopt(curl, CURLOPT_USERPWD, rpcauth.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(data));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
// Stop memory leak from headers
curl_slist_free_all(rpcheaders);
if (res > 0)
{
_log(ERROR, "curl_rpccall", "Failed to receive reply from Gridcoin RPC <type=" + type + "> (" + curl_easy_strerror(res) + ")");
return false;
}
//curl_easy_reset(curl);
std::istringstream ssinput(buffertwo);
for (std::string line; std::getline(ssinput, line);)
reply.append(line);
_log(INFO, "curl_rpccall", "Successful RPC call <tpye=" + type + ">");
return true;
}
bool http_download(const std::string& url, const std::string& destination, const std::string& userpass)
{
try {
FILE* fp;
fp = fopen(destination.c_str(), "wb");
if(!fp)
{
_log(ERROR, "url_http_download", "Failed to open file to download project data into <destination=" + destination + ">");
return false;
}
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writetofile);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);
curl_easy_setopt(curl, CURLOPT_USERPWD, userpass.c_str());
res = curl_easy_perform(curl);
fclose(fp);
if (res > 0)
{
if (fp)
fclose(fp);
_log(ERROR, "curl_http_download", "Failed to download file <urlfile=" + url + "> (" + curl_easy_strerror(res) + ")");
return false;
}
return true;
}
catch (std::exception& ex)
{
_log(ERROR, "curl_http_download", "Std exception occured (" + std::string(ex.what()) + ")");
return false;
}
}
bool http_header(const std::string& url, std::string& etag, const std::string& userpass)
{
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Accept: */*");
headers = curl_slist_append(headers, "User-Agent: curl/7.58.0");
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeheader);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &header);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);
curl_easy_setopt(curl, CURLOPT_USERPWD, userpass.c_str());
res = curl_easy_perform(curl);
// Stop memory leak from headers
curl_slist_free_all(headers);
if (res > 0)
{
_log(ERROR, "curl_http_header", "Failed to capture header of file <urlfile=" + url + ">");
return false;
}
std::istringstream ssinput(header);
for (std::string line; std::getline(ssinput, line);)
{
if (line.find("HTTP/") != std::string::npos)
{
// Check the code response in header to make sure everything is as it should be
std::vector<std::string> codevector = split(line, " ");
if (!httpcode(codevector[1], url))
return false;
}
if (line.find("ETag: ") != std::string::npos)
{
size_t pos;
std::string modstring = line;
pos = modstring.find("ETag: ");
etag = modstring.substr(pos+6, modstring.size());
etag = etag.substr(1, etag.size() - 3);
}
}
if (etag.empty())
{
_log(ERROR, "curl_http_header", "No ETag response from project url <urlfile=" + url + ">");
return false;
}
if (fDebug)
_log(INFO, "curl_http_header", "Captured ETag for project url <urlfile=" + url + ", ETag=" + etag + ">");
return true;
}
bool http_download(const std::string& url, const std::string& destination)
{
try {
FILE* fp;
fp = fopen(destination.c_str(), "wb");
if(!fp)
{
_log(ERROR, "url_http_download", "Failed to open file to download project data into <destination=" + destination + ">");
return false;
}
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writetofile);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
fclose(fp);
if (res > 0)
{
if (fp)
fclose(fp);
_log(ERROR, "curl_http_download", "Failed to download file <urlfile=" + url + "> (" + curl_easy_strerror(res) + ")");
return false;
}
return true;
}
catch (std::exception& ex)
{
_log(ERROR, "curl_http_download", "Std exception occured (" + std::string(ex.what()) + ")");
return false;
}
}
bool http_header(const std::string& url, std::string& etag)
{
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Accept: */*");
headers = curl_slist_append(headers, "User-Agent: curl/7.58.0");
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeheader);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &header);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_PROXY, "");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
// Stop memory leak from headers
curl_slist_free_all(headers);
if (res > 0)
{
_log(ERROR, "curl_http_header", "Failed to capture header of file <urlfile=" + url + ">");
return false;
}
std::istringstream ssinput(header);
for (std::string line; std::getline(ssinput, line);)
{
if (line.find("HTTP/") != std::string::npos)
{
// Check the code response in header to make sure everything is as it should be
std::vector<std::string> codevector = split(line, " ");
if (!httpcode(codevector[1], url))
return false;
}
if (line.find("ETag: ") != std::string::npos)
{
size_t pos;
std::string modstring = line;
pos = modstring.find("ETag: ");
etag = modstring.substr(pos+6, modstring.size());
etag = etag.substr(1, etag.size() - 3);
}
}
if (etag.empty())
{
_log(ERROR, "curl_http_header", "No ETag response from project url <urlfile=" + url + ">");
return false;
}
if (fDebug)
_log(INFO, "curl_http_header", "Captured ETag for project url <urlfile=" + url + ", ETag=" + etag + ">");
return true;
}
};
/**********************
* Network Node Logger *
**********************/
class logger
{
private:
std::ofstream logfile;
public:
logger()
{
fs::path plogfile = fs::current_path() / "scraper.log";
logfile.open(plogfile.c_str(), std::ios_base::out | std::ios_base::app);
if (!logfile.is_open())
printf("Logging : Failed to open logging file\n");
}
~logger()
{
if (logfile.is_open())
{
logfile.flush();
logfile.close();
}
}
void output(const std::string& tofile)
{
if (logfile.is_open())
logfile << tofile << std::endl;
return;
}
};
/**********************
* String Builder EXP *
**********************/
class stringbuilder
{
protected:
std::stringstream builtstring;
public:
void append(const std::string &value)
{
builtstring << value;
}
void append(double value)
{
builtstring << value;
}
void append(int64_t value)
{
builtstring << value;
}
void cleanappend(const std::string& value)
{
builtstring << value.substr(1, value.size());
}
void nlcleanappend(const std::string& value)
{
builtstring << value.substr(1, value.size()) << "\n";
}
void nlappend(const std::string& value)
{
builtstring << value << "\n";
}
void xmlappend(const std::string& xmlkey, const std::string& value)
{
builtstring << "<" << xmlkey << ">" << value << "</" << xmlkey << ">\n";
}
void xmlappend(const std::string& xmlkey, int64_t value)
{
builtstring << "<" << xmlkey << ">" << value << "</" << xmlkey << ">\n";
}
std::string value()
{
// Prevent a memory leak
const std::string& out = builtstring.str();
return out;
}
size_t size()
{
const std::string& out = builtstring.str();
return out.size();
}
void clear()
{
builtstring.clear();
builtstring.str(std::string());
}
};
/*********************
* Whitelist Data *
*********************/
class gridcoinrpc
{
private:
std::string whitelistrpcdata = "";
std::string superblockage = "";
public:
gridcoinrpc()
{}
~gridcoinrpc()
{}
bool wlimport()
{
whitelistrpcdata = "";
Json::Value jsonvalue;
Json::Reader jsonreader;
Json::StreamWriterBuilder valuestring;
Json::Value::const_iterator jsondata;
// Call RPC for the data
statscurl wl;
if (!wl.rpccall("listdata", "project", whitelistrpcdata))
{
_log(ERROR, "whitelist_data_import", "Failed to receive RPC reply for whitelist data");
return false;
}
if (whitelistrpcdata.find("\"result\":null") != std::string::npos)
{
_log(ERROR, "whitelist_data_import", "RPC replied with error (" + whitelistrpcdata + ")");
return false;
}
// Try to parse json data.
bool successparse = jsonreader.parse(whitelistrpcdata, jsonvalue);
if (!successparse)
{
printf("Failed to parse\n");
return false;
}
const Json::Value whitelist = jsonvalue["result"];
// Populate the beacon report data into scraper since we got a reply of whitelist
vwhitelist.clear();
for (jsondata = whitelist.begin() ; jsondata != whitelist.end(); jsondata++)
{
valuestring.settings_["indentation"] = "";
std::string outurl = Json::writeString(valuestring, *jsondata);
if (jsondata.key().asString() == "Key Type")
continue;
vwhitelist.push_back(std::make_pair(jsondata.key().asString(), outurl.substr(1, (outurl.size() - 2))));
}
return true;
}
int64_t sbage()
{
Json::Value jsonvalue;
Json::Reader jsonreader;
Json::StreamWriterBuilder valuestring;
Json::Value::const_iterator jsondata;
superblockage = "";
// Call RPC for the data
statscurl age;
if (!age.rpccall("superblockage", "", superblockage))
{
_log(ERROR, "superblockage_data_import", "Failed to receive RPC reply for superblock data");
return -1;
}
if (superblockage.find("\"result\":null") != std::string::npos)
{
_log(ERROR, "superblockage_data_import", "RPC replied with error (" + superblockage + ")");
return -2;
}
// Try to parse json data.
bool successparse = jsonreader.parse(superblockage, jsonvalue);
if (!successparse)
{
printf("Failed to parse\n");
return -3;
}
try
{
const Json::Value superblockdata = jsonvalue["result"];
for (jsondata = superblockdata.begin() ; jsondata != superblockdata.end(); jsondata++)
{
valuestring.settings_["indentation"] = "";
std::string outage = Json::writeString(valuestring, *jsondata);
if (jsondata.key().asString() == "Superblock Age")
{
printf("Outage is %s\n", outage.c_str());
return std::stoll(outage);
}
}
return -4;
}
catch (std::exception& ex)
{
_log(ERROR, "superblockage_data_import", "Exception occured (" + std::string(ex.what()) + ")");
return -5;
}
return -6;
}
};
/*********************
* Userpass Data *
*********************/
class userpass
{
private:
std::ifstream userpassfile;
public:
userpass()
{
vuserpass.clear();
fs::path plistfile = fs::current_path() / "userpass.dat";
userpassfile.open(plistfile.c_str(), std::ios_base::in);
if (!userpassfile.is_open())
_log(CRITICAL, "userpass_data", "Failed to open userpass file");
}
~userpass()
{
if (userpassfile.is_open())
userpassfile.close();
}
bool import()
{
vuserpass.clear();
std::string inputdata;
try
{
while (std::getline(userpassfile, inputdata))
{
std::vector<std::string>vlist = split(inputdata, ";");
vuserpass.push_back(std::make_pair(vlist[0], vlist[1]));
}
_log(INFO, "userpass_data_import", "Userpass contains " + std::to_string(vuserpass.size()) + " projects");
return true;
}
catch (std::exception& ex)
{
_log(CRITICAL, "userpass_data_import", "Failed to userpass import due to exception (" + std::string(ex.what()) + ")");
return false;
}
}
};
/*********************
* Auth Data *
*********************/
class authdata
{
private:
std::ofstream oauthdata;
stringbuilder outdata;
public:
authdata(const std::string& project)
{
std::string outfile = project + "_auth.dat";
fs::path poutfile = fs::current_path() / outfile.c_str();
oauthdata.open(poutfile.c_str(), std::ios_base::out | std::ios_base::app);
if (!oauthdata.is_open())
_log(CRITICAL, "auth_data", "Failed to open auth data file");
}
~authdata()
{
if (oauthdata.is_open())
oauthdata.close();
}
void setoutputdata(const std::string& type, const std::string& name, const std::string& etag)
{
outdata.clear();
outdata.append("<auth><etag>");
outdata.append(etag);
outdata.append("</etag>");
outdata.append("<type>");
outdata.append(type);
outdata.nlappend("</type></auth>");
}
bool xport()
{
try
{
if (outdata.size() == 0)
{
_log(CRITICAL, "user_data_export", "No authentication etags to be exported!");
return false;
}
oauthdata.write(outdata.value().c_str(), outdata.size());
_log(INFO, "auth_data_export", "Exported");
return true;
}
catch (std::exception& ex)
{
_log(CRITICAL, "auth_data_export", "Failed to export auth data due to exception (" + std::string(ex.what()) + ")");
return false;
}
}
};
/**********************
* Network Node Tester *
**********************/
class nntester
{
private:
std::ofstream logfile;
public:
nntester()
{
fs::path plogfile = fs::current_path() / "scraper.time";
logfile.open(plogfile.c_str(), std::ios_base::out | std::ios_base::app);
if (!logfile.is_open())
printf("Logging : Failed to open logging file\n");
}
~nntester()
{
if (logfile.is_open())
{
logfile.flush();
logfile.close();
}
}
void output(const std::string& tofile)
{
if (logfile.is_open())
logfile << tofile << std::endl;
return;
}
};
#endif // SCRAPER_H