-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
192 lines (163 loc) · 5.27 KB
/
main.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
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
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;
//Create an instance of a user
struct User {
string app_id;
int device_id;
string identifier;
string identifier_auth_hash;
string test_type;
string language;
string external_user_id;
string external_user_id_auth_hash;
string timezone;
string game_version;
string device_model;
string device_os;
int session_count;
double amount_spent;
int created_at;
int playtime;
int last_active;
int notification_types;
double lat;
double lon;
string country;
string timezone_id;
vector<pair<string,string>> tags;
};
#define PRINT_MEMBERS(a) \
cout << #a << ": " << a << endl;
void printUser(User user) {
PRINT_MEMBERS(user.app_id);
PRINT_MEMBERS(user.device_id);
PRINT_MEMBERS(user.identifier);
PRINT_MEMBERS(user.identifier_auth_hash);
PRINT_MEMBERS(user.test_type);
PRINT_MEMBERS(user.language);
PRINT_MEMBERS(user.external_user_id);
PRINT_MEMBERS(user.external_user_id_auth_hash);
PRINT_MEMBERS(user.timezone);
PRINT_MEMBERS(user.game_version);
PRINT_MEMBERS(user.device_model);
PRINT_MEMBERS(user.device_os);
PRINT_MEMBERS(user.session_count);
PRINT_MEMBERS(user.amount_spent);
PRINT_MEMBERS(user.created_at);
PRINT_MEMBERS(user.playtime);
PRINT_MEMBERS(user.last_active);
PRINT_MEMBERS(user.notification_types);
PRINT_MEMBERS(user.lat);
PRINT_MEMBERS(user.lon);
PRINT_MEMBERS(user.country);
PRINT_MEMBERS(user.timezone_id);
for(auto &[key, value] : user.tags) {
cout << "user.tags : " << key << "," << value << endl;
}
}
void makeCurlRequest(User &user){
printUser(user);
}
int main() {
//open the csv in directory named "input"
ifstream input("input.csv");
//Throw error if unable to open
if(!input.is_open()) {
cout << "Sorry, unable to open file please try again" << endl;
}
//Define line of csv that is going to be read
string line;
//ignore the column names in the first line when making the request
input.ignore(numeric_limits<streamsize>::max(),'\n');
//While there are lines in the csv
while(getline(input, line)){
//create a stringstream object from the line
stringstream ss(line);
//Define a new user
User user;
//Change the properties of the user by assigning from the csv
getline(ss, user.app_id, ',');
//Declare string for device_id
string device_id;
//We need to pull the value out as a string and change cast to int
getline(ss, device_id, ',');
//We check for empty string, and if not, use strint to int method
if(!device_id.empty()) {
user.device_id = stoi(device_id);
} else {
user.device_id = 0;
}
getline(ss, user.identifier, ',');
getline(ss, user.identifier_auth_hash, ',');
getline(ss, user.test_type, ',');
getline(ss, user.language, ',');
getline(ss, user.external_user_id, ',');
getline(ss, user.external_user_id_auth_hash, ',');
getline(ss, user.timezone, ',');
getline(ss, user.game_version, ',');
getline(ss, user.device_model, ',');
getline(ss, user.device_os, ',');
string session_count;
getline(ss, session_count, ',');
if(!session_count.empty()) {
user.session_count = stoi(session_count);
}
string amount_spent;
getline(ss, amount_spent, ',');
if(!amount_spent.empty()) {
user.amount_spent = stod(amount_spent);
}
string created_at;
getline(ss, created_at, ',');
if(!created_at.empty()){
user.created_at = stoi(created_at);
}
string playtime;
getline(ss, playtime, ',');
if(!playtime.empty()) {
user.playtime = stoi(playtime);
}
string last_active;
getline(ss, last_active, ',');
if(!last_active.empty()) {
user.last_active = stoi(last_active);
}
string notification_types;
getline(ss, notification_types, ',');
if(!notification_types.empty()) {
user.notification_types = stoi(notification_types);
}
string lat;
getline(ss, lat, ',');
if(!lat.empty()) {
user.lat = stod(lat);
}
string lon;
getline(ss, lon, ',');
if(!lon.empty()) {
user.lon = stod(lon);
}
getline(ss, user.country, ',');
getline(ss, user.timezone_id, ',');
//Allow multiple tags to be uploaded for each user that is going to be created.
string tagsLine;
getline(ss, tagsLine);
stringstream tagss(tagsLine);
string tag;
while(getline(tagss, tag, ',')) {
string key, value;
stringstream tagstream(tag);
getline(tagstream, key, ':');
getline(tagstream, value, ':');
user.tags.push_back(make_pair(key, value));
}
//TODO loop through user properties and put anything with a value into the curl request
makeCurlRequest(user);
}
input.close();
return 0;
}