-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreatePopInfile.cpp
43 lines (38 loc) · 1.28 KB
/
CreatePopInfile.cpp
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
//
// Created by kwoodle on 11/23/19.
//
#include <ktrade/Ksql.h>
#include <ktrade/Util.h>
using namespace std;
int main() {
bool do_build{true}; // does table need to be built?
bool do_test(true); // test if table is ok
const string service = "localhost";
const string user = "kwoodle";
const string pass = "Rancity1!";
const string table = "apportion";
const string database = "census";
drk::MySqlOptions opts;
drk::KSql kSql(opts);
kSql.Execute("use " + database);
const string csv_file = "/home/kwoodle/Documents/Census/data/est2018-01.csv";
const string csv_outfile = "/home/kwoodle/Documents/Census/data/est2018fixed.csv";
ofstream ofile(csv_outfile);
if (do_build) {
ifstream csv_in(csv_file);
if (!csv_in.is_open()) {
cout << "Failed to open csv file " << csv_file << endl;
return 1;
}
string line;
while (getline(csv_in, line)) {
// remove those pesky commas
line.erase(std::remove(line.begin(), line.end(), ','), line.end());
// and periods
line.erase(std::remove(line.begin(), line.end(), '.'), line.end());
cout << line << endl;
ofile << line << endl;
}
}
return 0;
}