Last active
January 1, 2016 22:39
-
-
Save aallan/8211440 to your computer and use it in GitHub Desktop.
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.
This file contains 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
#!/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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment