-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson-counts
More file actions
executable file
·386 lines (347 loc) · 8.53 KB
/
json-counts
File metadata and controls
executable file
·386 lines (347 loc) · 8.53 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
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
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use File::Slurp qw(read_file);
use JSON::MaybeXS qw(decode_json);
# still used for validation
my $location_filename = 'location_history/your_location_history.json';
my ($data_dir) = @ARGV;
validate_dir($data_dir);
our @generic_index = (
{
key => 'history',
filename => 'ads/ads_interests.json',
typename => 'ad interests'
},
{
key => 'history',
filename => 'ads/advertisers_who_uploaded_a_contact_list_with_your_information.json',
typename => 'advertiser uploaded contact'
},
{
key => 'history',
filename => 'ads/advertisers_you\'ve_interacted_with.json',
typename => 'advertiser touched'
},
{
key => 'installed_apps',
filename => 'apps_and_websites/apps_and_websites.json',
typename => 'installed_apps'
},
{
key => 'app_posts',
filename => 'apps_and_websites/posts_from_apps_and_websites.json',
typename => 'app_post'
},
{
key => 'comments',
filename => 'comments/comments.json',
typename => 'comment'
},
{
key => 'events_invited',
filename => 'events/event_invitations.json',
typename => 'events_invited'
},
{
key => 'pages_followed',
filename => 'following_and_followers/followed_pages.json',
typename => 'followed page'
},
{
key => 'following',
filename => 'following_and_followers/following.json',
typename => 'following'
},
{
key => 'friends',
filename => 'friends/friends.json',
typename => 'friends'
},
{
key => 'received_requests',
filename => 'friends/received_friend_requests.json',
typename => 'received friends requests'
},
{
key => 'rejected_requests',
filename => 'friends/rejected_friend_requests.json',
typename => 'rejected friends requests'
},
{
key => 'sent_requests',
filename => 'friends/sent_friend_requests.json',
typename => 'sent friend requests'
},
{
key => 'groups_joined',
filename => 'groups/your_group_membership_activity.json',
typename => 'groups joined'
},
{
key => 'group_posts',
filename => 'groups/your_posts_and_comments_in_groups.json',
typename => 'group_posts'
},
{
key => 'other_likes',
filename => 'likes_and_reactions/likes_on_external_sites.json',
typename => 'other like'
},
{
key => 'page_likes',
filename => 'likes_and_reactions/pages.json',
typename => 'page like'
},
{
key => 'reactions',
filename => 'likes_and_reactions/posts_and_comments.json',
typename => 'reaction'
},
{
key => 'location_history',
filename => 'location_history/your_location_history.json',
typename => 'location'
},
{
key => 'pokes',
filename => 'other_activity/pokes.json',
typename => 'pokes'
},
{
key => 'pages',
filename => 'pages/your_pages.json',
typename => 'pages'
},
{
key => 'wall_posts_sent_to_you',
filename => 'posts/other_people\'s_posts_to_your_timeline.json',
typename => 'wall_posts_sent_to_you'
},
{
# TODO: status updaetes per year/month
key => 'status_updates',
filename => 'posts/your_posts.json',
typename => 'status update'
},
{
key => 'profile_updates',
filename => 'profile_information/profile_update_history.json',
typename => 'profile_updates'
},
{
key => 'searches',
filename => 'search_history/your_search_history.json',
typename => 'searches'
},
{
key => 'account_activity',
filename => 'security_and_login_information/account_activity.json',
typename => 'account_activity'
},
{
key => 'admin_records',
filename => 'security_and_login_information/administrative_records.json',
typename => 'admin_records'
},
{
key => 'recognized_devices',
filename => 'security_and_login_information/authorized_logins.json',
typename => 'recognized_devices'
},
{
key => 'login_protection_data',
filename => 'security_and_login_information/login_protection_data.json',
typename => 'login_protection_data'
},
{
key => 'account_accesses',
filename => 'security_and_login_information/logins_and_logouts.json',
typename => 'account_accesses'
},
{
key => 'used_ip_address',
filename => 'security_and_login_information/used_ip_addresses.json',
typename => 'used_ip_address'
},
{
key => 'active_sessions',
filename => 'security_and_login_information/where_you\'re_logged_in.json',
typename => "active session"
},
{
key => 'your_places',
filename => 'your_places/places_you\'ve_created.json',
typename => "places you've created"
},
{
key => '', # just a hash
skip => 1,
filename => 'about_you/face_recognition.json',
typename => ''
},
{
key => '', # tiny
skip => 1,
filename => 'about_you/friend_peer_group.json',
typename => 'friend_peer_group'
},
{
key => '', # address_book -> address_book
skip => 1,
filename => 'about_you/your_address_books.json',
typename => 'address_book'
},
{
key => '', # 3 subkeys
skip => 1,
filename => 'events/your_event_responses.json',
typename => 'event_responses'
},
{
key => '', # payments -> payments
skip => 1,
filename => 'payment_history/payment_history.json',
typename => 'payments'
},
{
key => '',
skip => 1,
filename => 'photos_and_videos/album/0.json',
typename => ''
},
{
key => '', # not countable
skip => 1,
filename => 'profile_information/profile_information.json',
typename => 'profile'
},
);
count_marketplace();
count_saved_items();
do_generics();
do_messages();
#
# count functions
#
sub count_saved_items {
my $no_saved_items_filename = 'saved_items/no-data.txt';
if (-f $no_saved_items_filename) {
print "- 0 saved_items entries\n";
} else {
warn "unimplemented saved_items count"; # TODO: implement
}
}
sub count_marketplace {
my $no_marketplace_filename = 'marketplace/no-data.txt';
if (-f $no_marketplace_filename) {
print "- 0 marketplace entries\n";
} else {
warn "unimplemented marketplace count"; # TODO: implement
}
}
#
# messages
#
sub do_messages {
my $conversations = `find messages -name message.json`;
my @conversations = split(/\n/,$conversations);
my $conversation_count = scalar(@conversations);
print "- $conversation_count conversations found in Facebook Messages\n";
my $total_messages = 0;
foreach my $convo_filename (@conversations) {
my $conversation = read_json($convo_filename);
my $title = $conversation->{'title'}; # usually the other person
# count messages
my @things = @{$conversation->{'messages'}};
my $count = scalar @things;
$total_messages += $count;
# parse out bucket from filename
my(undef, $bucket) = split(m{[/]}, $convo_filename);
print "+ $count messages with $title ($bucket)\n";
}
print "- $total_messages messages in those $conversation_count conversations\n";
}
#
# generics
#
sub do_generics {
foreach my $generic (@generic_index) {
my $key = $generic->{key};
my $filename = $generic->{filename};
my $typename = $generic->{typename};
my $skip = $generic->{skip} || 0;
if ($skip) {
print "... skipping $filename which isn't generic enough to process yet.\n";
next; # skip!
}
if (length $key) {
count_generic($filename,$typename,$key);
} else {
top_keys_file($filename);
}
}
}
sub count_generic {
my ($filename,$type,$key) = @_;
unless (-f $filename) {
warn "no such file as $filename";
return;
}
my $hash = read_json($filename);
my @things = @{$hash->{$key}};
my $count = scalar @things;
print "- $count $type entries\n";
}
#
# utility functions
#
sub top_keys {
my ($hash) = @_;
my @keys = keys %$hash;
print " % " . join("\n % ", @keys) . "\n";
}
sub top_keys_file {
my ($filename) = @_;
my $hash = read_json($filename);
print " + $filename :\n";
top_keys($hash);
}
sub read_json {
my ($json_filename) = @_;
my $file_contents = read_file($json_filename);
my $json = JSON::MaybeXS->new->allow_nonref;
my $js_ref = $json->decode($file_contents);
die "no ref back from json->decode()" unless $js_ref;
return $js_ref;
}
#
# sanity check
#
sub validate_dir {
my ($data_dir) = @_;
# is it a directory???
unless (-d $data_dir) {
die "not a directory: $data_dir";
}
chdir($data_dir) or die "couldn't chdir($data_dir): $!";
# does it contain the right subdirectories???
my @top_dirs = qw( about_you ads apps_and_websites calls_and_messages
comments events following_and_followers friends
groups likes_and_reactions location_history
marketplace messages other_activity pages
payment_history photos_and_videos posts
profile_information saved_items search_history
security_and_login_information your_places);
foreach my $dir (@top_dirs) {
unless (-d $dir) {
die "no $dir directory in $data_dir";
}
}
# how about a file?
unless (-f $location_filename) {
die "no $location_filename";
}
print "$data_dir looks like a Facebook data dump\n";
}