Huff, Puff, METADATA

humorously, for a new project i’m working on, i created a metadata inflater in perl. it’s raison d’etre is to convert nokia’s lifeblog-format SMS files to something we can load into our DB. nokia doesn’t store any of the relevant metadata within the SMS files, so since it’s only test data, i make up the metadata… but in a realistic way.

the sender and recipients are randomly swapped back and forth to simulate realistic two-way SMS traffic. the date/time stamps are random but believeable. it’s great!


#!/usr/bin/perl
use strict;
use Time::Local;

my $recip = "2482190031";
my @senders;
@senders = ( "9176017882", "2487370144", "5869864509", "(202) 431-9457" );

while( ) {

# pick a random sender and strip any non-numerics
my $sender = $senders[ int( rand() * scalar @senders )];
$sender =~ s/[^\d]//g;

# randomly flop sender and recip to simulate normal back-and-forth message traffic
# (Nb. that we are the only recipient)
if( int( rand() * 10) % 2 == 0 ) {
my $tmp = $recip;
$recip = $sender;
$sender = $tmp;
}

print "TO: $recip\n";
print "FROM: $sender\n";
print "MESSAGE_ID: " . (rand() * 9999999999) . "\n";

# forge a realistic date
my $time = timelocal(int(60*rand()), int(60*rand()), int(23*rand()),int( 28 * rand() + 1), (int( 11*rand())), 103 + (int( 2 * rand())));
my $string = localtime $time;
print "DATE: $string\n";

# finally, print the message:
print "$_\n";
print "\n";
}