-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter_test.cpp
More file actions
290 lines (273 loc) · 7.62 KB
/
twitter_test.cpp
File metadata and controls
290 lines (273 loc) · 7.62 KB
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
#include "src/Json.h"
#include <fstream>
struct Metadata {
std::string result_type;
std::string iso_language_code;
JSONABLE(Metadata);
};
SET_JSONABLE(Metadata, result_type, iso_language_code);
struct Url {
std::string url;
std::string expanced_url;
std::string display_url;
unsigned indices[2];
JSONABLE(Url);
};
SET_JSONABLE(Url, url, expanced_url, display_url, indices);
struct Urls {
std::vector<Url> urls;
JSONABLE(Urls);
};
SET_JSONABLE(Urls, urls);
struct Size {
unsigned w;
unsigned h;
std::string resize;
JSONABLE(Size);
};
SET_JSONABLE(Size, w, h, resize);
struct Sizes {
Size large;
Size medium;
Size thumb;
Size small;
JSONABLE(Sizes);
};
SET_JSONABLE(Sizes, large, medium, thumb, small);
struct UserMention {
std::string screen_name;
std::string name;
size_t id;
std::string id_str;
unsigned indices[2];
JSONABLE(UserMention);
};
SET_JSONABLE(UserMention, screen_name, name, id, id_str, indices);
struct HashTag {
std::string text;
int indices[2];
JSONABLE(HashTag);
};
SET_JSONABLE(HashTag, text, indices);
struct Media {
size_t id;
std::string id_str;
unsigned indices[2];
std::string media_url;
std::string media_url_https;
std::string url;
std::string display_url;
std::string type;
Sizes sizes;
size_t source_status_id;
std::string source_status_id_str;
JSONABLE(Media);
};
SET_JSONABLE(Media,
id,
id_str,
indices,
media_url,
media_url_https,
url,
display_url,
type,
sizes,
source_status_id,
source_status_id_str);
struct Entities {
std::vector<HashTag> hashtags;
std::vector<std::string> symbols;
Urls url;
std::vector<Url> urls;
std::vector<UserMention> user_mentions;
std::vector<Media> media;
JSONABLE(Entities);
};
SET_JSONABLE(Entities, hashtags, symbols, url, urls, user_mentions, media);
struct User {
size_t id;
std::string id_str;
std::string name;
std::string screen_name;
std::string location;
std::string description;
std::string* url;
Entities entites;
bool _protected;
size_t followers_count;
size_t friends_count;
size_t listed_count;
std::string created_at;
size_t favourites_count;
int* utc_offset;
std::string* time_zone;
bool verified;
size_t status_count;
std::string lang;
bool contributors_enabled;
bool is_translator;
bool is_translation_enabled;
std::string profile_background_color;
std::string profile_background_image_url;
std::string profile_background_image_url_https;
std::string profile_background_title;
std::string profile_image_url;
std::string profile_image_url_https;
std::string profile_banner_url;
std::string profile_link_color;
std::string profile_sidebar_border_color;
std::string profile_sidebar_fill_color;
std::string profile_text_color;
bool profile_use_background_image;
bool default_profile;
bool default_profile_image;
bool following;
bool follow_request_sent;
bool notifications;
JSONABLE(User);
};
SET_JSONABLE(User,
id,
id_str,
name,
screen_name,
location,
description,
url,
entites,
_protected,
followers_count,
friends_count,
listed_count,
created_at,
favourites_count,
utc_offset,
time_zone,
verified,
status_count,
lang,
contributors_enabled,
is_translator,
is_translation_enabled,
profile_background_color,
profile_background_image_url,
profile_background_image_url_https,
profile_background_title,
profile_image_url,
profile_image_url_https,
profile_banner_url,
profile_link_color,
profile_sidebar_border_color,
profile_sidebar_fill_color,
profile_text_color,
profile_use_background_image,
default_profile,
default_profile_image,
following,
follow_request_sent,
notifications);
struct Coordinate {
double x, y;
JSONABLE(Coordinate);
};
SET_JSONABLE(Coordinate, x, y);
struct Status {
Metadata metadata;
std::string created_at;
size_t id;
std::string id_str;
std::string text;
std::string source;
bool truncated;
size_t* in_reply_to_status_id;
std::string* in_reply_to_status_id_str;
size_t* in_reply_to_user_id;
std::string* in_reply_to_user_id_str;
std::string* in_reply_to_screen_name;
User user;
std::string* geo;
std::vector<Coordinate>* coordinates;
std::string* place;
std::vector<std::string>* contributors;
Status* retweeted_status;
size_t retweet_count;
size_t favorite_count;
Entities entities;
bool favorited;
bool retweeted;
std::string lang;
JSONABLE(Status);
};
SET_JSONABLE(Status,
metadata,
created_at,
id,
id_str,
text,
source,
truncated,
in_reply_to_status_id,
in_reply_to_status_id_str,
in_reply_to_user_id,
in_reply_to_user_id_str,
in_reply_to_screen_name,
user,
geo,
coordinates,
place,
contributors,
retweeted_status,
retweet_count,
favorite_count,
entities,
favorited,
retweeted,
lang);
struct SearchMetadata {
double completed_in;
size_t max_id;
std::string max_id_str;
std::string next_results;
std::string query;
std::string refresh_url;
size_t count;
size_t since_id;
std::string since_id_str;
JSONABLE(SearchMetadata);
};
SET_JSONABLE(SearchMetadata,
completed_in,
max_id,
max_id_str,
next_results,
query,
refresh_url,
count,
since_id,
since_id_str);
struct Twitter {
std::vector<Status> statuses;
// SearchMetadata search_metadata;
JSONABLE(Twitter);
};
SET_JSONABLE(Twitter, statuses);
struct A {
int x, y;
std::string f;
std::string* name;
A() { std::cout << "Ctor" << std::endl; }
JSONABLE(A);
};
SET_JSONABLE(A, x, y, name);
int main()
{
// std::ifstream file("test.json");
// cW::JsonParser parser(file);
// A* a = A::fromJson(parser.rootNode);
cW::Clock::start();
std::ifstream file("test_resources/twitter.json");
cW::JsonParser parser(file);
auto tweets = Twitter::parseJson(parser.rootNode);
std::cout << "Count of tweet statuses: " << tweets.statuses.size() << std::endl;
}