public
Last active

Perl script to go through the leaked Snapchat database of phone numbers and user names, and divide it into separate CSV files split by location. Will create a file for each location in a locations/ subdirectory in the current working directory. Will report the totals for each location in CSV format.

  • Download Gist
locations.pl
Perl
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
#!/usr/bin/perl
 
use strict;
 
print "Reading schat.csv\n";
unless ( open ( FILE, "<schat.csv") ) {
print "Cannot open file for read\n";
exit;
}
 
my @foo = <FILE>;
chomp( @foo );
close FILE;
 
print "Checking for locations directory\n";
mkdir "locations" unless -d "locations";
 
print "Processing...\n";
my %locations;
foreach my $foo ( @foo ) {
$foo =~ s/"$//;
$foo =~ s/^"//;
$foo =~ s/","/,/g;
my @bar = split ",", $foo;
 
if( exists $locations{$bar[2]} ) {
$locations{$bar[2]} += 1;
} else {
$locations{$bar[2]} = 1;
}
unless ( open ( FILE, ">>locations/$bar[2].csv") ) {
print "Cannot open $bar[2].csv for write";
exit;
}
print FILE "$foo\n";
close(FILE);
}
 
my $total = 0;
foreach my $key (sort keys %locations) {
print "$key,$locations{$key}\n";
$total = $total + $locations{$key};
}
print "Total = $total\n";
 
exit;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.