Last active
December 16, 2015 06:59
-
-
Save briandfoy/5395918 to your computer and use it in GitHub Desktop.
Sequence a Crowdtilt campaign
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Users/brian/bin/perls/perl5.14.2 | |
use v5.14; | |
use Email::MIME; | |
use Date::Parse qw(str2time); | |
# /Users/brian/Library/Mail/V2/[email protected]/Pinto Campaign.mbox/52D05AC0-3807-4D78-9864-069A09964592/Data/6/0/4/2/Messages | |
# I'm grabbing the messages out of Apple's Mail, which is fine I guess. | |
# I have a filter set up for the messages I want. | |
# If I really wanted something fancy, I'd pull out procmail. | |
my $folder = $ARGV[0] // q(messages); | |
chdir $folder or die "Could not change to $folder\n$!\n"; | |
my @files = glob( "*.emlx" ); | |
my $total = 0; | |
# any event that we might care about. I try to get as precise a time | |
# as possible, but many things hide the time. I think Twitter and | |
# Google Plus show it in local time, so my times are in CST | |
# | |
# I'm not sure about blogs.perl.org timezones | |
my @records = ( | |
#Date: Sun, 7 Apr 2013 19:19:27 +0200 | |
[ 'https://twitter.com/briandfoy_perl/status/320705368114212864', 'Apr 6, 2013 6:11 PM CST' ], | |
[ 'http://babyl.dyndns.org/techblog/entry/flattr', 'April 7 2013' ], | |
[ 'http://perlmonks.org/?node_id=1027606', 'Apr 08, 2013, 22:44' ], | |
[ 'http://blogs.perl.org/users/brian_d_foy/2013/04/crowd-funding-pinto.html', 'April 10, 2013 8:31 AM GMT' ], | |
[ 'https://plus.google.com/114881374586776746383/posts/JPKGfQs3RNe', 'Apr 10, 2013' ], | |
[ 'https://twitter.com/perlbuzz/status/322485023385194496', 'Apr 11, 2013 4:03 PM CST' ], | |
[ 'https://plus.google.com/105487854388646525021/posts/PYc8tBKPC4s', 'Apr 11, 2013' ], | |
[ 'https://plus.google.com/111953452408039695896/posts/jNoSjtbaAoX', 'Apr 11, 2013' ], | |
[ 'https://plus.google.com/106327682444395535531/posts/cC4Pn84Vn9v', 'Apr 11, 2013' ], | |
[ 'https://plus.google.com/112213852555548050807/posts/fZcTuNHVx9r', 'Apr 11, 2013' ], | |
[ 'https://plus.google.com/102102661880254943196/posts/HpZG9Z5VUf1', 'Apr 13, 2013' ], | |
[ 'http://blogs.perl.org/users/jeff_thalhammer1/2013/04/a-dead-simple-cpan-api.html', 'April 15, 2013 11:00 PM GMT' ], | |
[ 'http://perlweekly.com/archive/90.html', 'April 15, 2013' ], | |
[ 'https://news.ycombinator.com/item?id=5534353', 'April 9, 2013' ], | |
[ 'https://pay.reddit.com/r/perl/comments/1c6z3n/crowd_funding_pinto/', 'April 9, 2013' ], | |
[ 'http://blogs.perl.org/users/sawyer_x/2013/05/why-you-should-help-crowd-fund-pinto.html', 'May 1, 2013 11:13 AM' ], | |
[ 'http://blogs.perl.org/users/brian_d_foy/2013/04/contribute-to-pinto-through-paypal-or-flattr.html', 'April 30, 2013 5:53 PM' ], | |
[ 'http://perlmaven.com/videos/jeffrey-thalhammer-perl-critic-and-pinto', '' ] | |
[ 'http://perlnews.org/2013/05/infinity-interactive-tilts-perl-crowdfunding-drive/', 'May 1, 2013 18:51' ] | |
); | |
foreach my $file ( @files ) { | |
my $data = do { local( @ARGV, $/ ) = $file; <> }; | |
my $email = Email::MIME->new( $data ); | |
# my filter catches some I forwarded myself, so only take | |
# the ones from Crowdtilt | |
my $from = $email->header( 'From' ); | |
next unless $from =~ m/\bnoreply\@crowdtilt.com\b/; | |
my $body = $email->body; | |
my( $profile, $name, $amount ) = $body =~ m{ | |
<p><a.*?href="(.*?)".*?>(.*?)</a> | |
\s+ has \s+ just \s+ | |
.*? | |
<p>Amount:\s+(\S+)\s*</p> | |
}xs; | |
my $date = $email->header( 'Date' ); | |
push @records, [ $file, $date, $amount, $name, $profile ]; | |
$total += $amount =~ s/\A\$//r; | |
} | |
say "Total is $total"; | |
say "Processed " . @files . " messages; counted " . @records; | |
say | |
join "\n", | |
map { join( "\t", @$_ ) } | |
map { $_->[1] } | |
sort { $a->[0] <=> $b->[0] } | |
map { [ str2time($_->[1]), $_ ] } | |
@records; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment