-
Notifications
You must be signed in to change notification settings - Fork 0
/
calls_parse.pl
executable file
·106 lines (82 loc) · 2 KB
/
calls_parse.pl
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
#!/usr/bin/env perl
# I would prefer to do this manually, but, I'm gonna have to use Mojo::DOM because
# I do not trust google's output to always be consistent
use Mojo::DOM;
use Data::Dumper;
# Parse args
if(!$ARGV[0]) {
die("Usage: $0 [9 digit phone number 1112223333 no +1] [Optional folder. Defaults to Calls/] \n");
}
$my_number = '+1'. $ARGV[0];
if($ARGV[1]) {
$calls_dir = $ARGV[1];
} else {
$calls_dir = "Calls/";
}
print STDERR "Parsing messages WRT $my_number from $calls_dir\n";
opendir my $dh, $calls_dir;
@files = readdir $dh;
local $/; #Enable local slurp mode
my $limitcounter;
my $limit = 40;
my @text_clusters;
foreach(@files) {
if($_ =~ m/Text/) {
open my $fh, '<', "$calls_dir/$_" or die "can't open $file: $!";
$input_file = <$fh>;
$dom = Mojo::DOM->new($input_file);
my $other_subject = $_;
@fragments = split / - Text - /, $other_subject;
$other_subject = shift(@fragments);
my @timestamp, @sender, @quotes;
@eachmessage = $dom->find('div.message')->each();
foreach(@eachmessage) {
$message = Mojo::DOM->new($_);
@abbr = $message
->find('abbr')
->map(attr => "title")
->each();
push @timestamp, shift(@abbr);
# Sender
$sender = $message
->find('a')
->map( attr => 'href' )
->join("\n");
$sender =~ s/tel\://;
push @sender, $sender;
if($sender == "") {
last;
print "timestamp: $timestamp | sender: $sender | message: $message\n";
die("Fuck");
}
if($sender != $my_number) {
if($sender != $other_subject) {
$other_subject = $sender;
}
}
# Message
$quotes = $message
->find('q')
->join("\n");
$quotes =~ s/\<q\>//;
$quotes =~ s/\<\/q\>//;
push @quotes, $quotes;
}
close($fh);
foreach(@timestamp) {
print $_;
print "\t";
$i = pop @sender;
if($i == $my_number) {
print "Outgoing\t$other_subject\t";
} else {
print "Incoming\t$i\t";
}
print pop @quotes;
print "\n";
}
@timestamp = "";
@sender = "";
@quotes = "";
}
}