forked from ZachGoldberg/Wine-Weekly-Newsletter-Tools
/
kcstats2
executable file
·171 lines (125 loc) · 2.96 KB
/
kcstats2
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
#!/usr/bin/perl
#takes two textfiles as input: this month and last one.
use HTTP::Date;
$file = shift || die "No file specified";
$inp;
$msgs=0;
$fsa=1;
open(I, "<$file");
while ($_ = <I>) {
if ($fsa && $_ =~ /^From /) {
$msgs++;
}
$inp[$msgs] .= $_;
chomp;
if (!length($_)) {
$fsa=1;
}
else{
$fsa=0;
}
}
close I;
$prev = shift || die "No file specified";
open(I, "<$prev");
while ($_ = <I>) {
if ($fsa && $_ =~ /^From /) {
$msgs++;
}
$inp[$msgs] .= $_;
chomp;
if (!length($_)) {
$fsa=1;
}
else{
$fsa=0;
}
}
close I;
# Only use the last 14 days and split them up in two weeks
$msgs=0;
$epoc = time();
$epoc07 = $epoc - 07 * 24 * 60 * 60;
$epoc14 = $epoc - 14 * 24 * 60 * 60;
foreach my $msg (@inp) {
if ($msg =~ /^From\s+.*at.*\.(.*)$/m) {
#print "$1\n";
} else {
next;
}
if ($1 =~ / (.*)$/m) {
$dt = str2time($1);
if ($dt > $epoc07) {
$msgs++;
$file[$msgs] = $msg;
} elsif ($dt > $epoc14) {
$msgs++;
$prev[$msgs] = $msg;
}
}
}
# Find the number of posts
$posts = scalar(@file);
# Find the size of the list in K
$size = int(length(join '', @file) / 1024);
# Find how many people posted
foreach (@file) {
/^From:\s+(.*)\s+(\(.*)$/m;
$mails{$1}=$2;
}
foreach (@file) {
/^From:\s+(.*)\s+\(.*$/m;
$whomail=$1." ".$mails{$1};
if(! defined ($posters{$whomail})) {
$numposters++;
}
$posters{$whomail} += length;
$posterposts{$whomail} ++;
}
foreach (@prev) {
/^From:\s+(.*)$/m;
$prevposters{$1} += length;
}
# Find how many people posted more than once
$ot = 0;
foreach (keys %posterposts) {
($posterposts{$_} > 1) && ($ot++);
}
# Find how many posted last week too
$lw = 0;
foreach (keys %prevposters) {
if($posters{$_}) {
$lw++;
}
}
# Find the biggest posters of the week.
sub bysizes {
if($posterposts{$b} == $posterposts{$a}) {
return $posters{$b} <=> $posters{$a};
}
return $posterposts{$b} <=> $posterposts{$a};
}
$onlyeleven=0;
foreach (sort bysizes keys %posterposts) {
$who = $_;
#get rid of email addresses
if(($who =~ /\S\s+(\S*)@\S*/) || ($who =~ /(\S*)@\S*\s+\S/))
{
$who =~ s/\S*@\S*//;
}
else
{
$who =~ s/<?(\S*)@\S*/($1)/;
}
$who =~ s/</</g;
$who =~ s/>/>/g;
$who =~ s/"/"/g;
$who =~ s/\s*$//;
$who || next;
$onlyeleven++;
if ($onlyeleven > 11) {last;}
push @whos, sprintf "<person posts=\"%d\" size=\"%d\" who=\"%s\" />\n", $posterposts{$_}, $posters{$_}/1024, $who;
}
print "<stats posts=\"$posts\" size=\"$size\" contrib=\"$numposters\" multiples=\"$ot\" lastweek=\"$lw\">\n\n";
print @whos;
print "\n</stats>\n";