use DBI; use String::Random; use Data::Random qw(rand_date); use Data::Random::WordList; use strict; my $MODE = $ARGV[0]; my $dsn = "dbi:mysql:lycianetwork:localhost:3306"; my $dbh = DBI->connect($dsn,"root", "", { RaiseError => 1, AutoCommit => 0 }) || die "Unable to connect to localhost because $DBI::errstr"; my $sr = new String::Random; my $wl = new Data::Random::WordList(); my %location = ( Kas=>["Merkez","Cukurbag","Bayindir","BuyukCakil","Kucuk Cakil","Baldiraz","Mumuda"], Bodrum=>["Akyaka","Turgut Reis","Yali Ciftlik","Merkez","Torba","Bitez","Gumbet","Golkoy","Turkbuku"], Fethiye=>["Kayakoy","Merkez","Oludeniz","Calis Beach","Dalyan"], Antalya=>["Lara"], Milas=>["Gumusluk","Comakdag","Bafa Golu"], Kalkan=>["Merkez","Sari Belen","Esen"], Finike=>["Merkez","Liman"], Demre=>["Merkez"], Kemer=>["Merkez","Camyuva","Beldibi","Belek"] ); my @status = qw/fs r s/; my @type = qw/plot villa flat/; my @location = keys %location; if($MODE eq "member"){ foreach(11..1000){ my $mem = &generate_member($_); $dbh->do("INSERT INTO members VALUES( $mem )"); } } elsif($MODE eq "pr"){ foreach(10..3000){ my $ownerid = int( rand(1001 ) ); my $pr = &generate_property($ownerid); $dbh->do("INSERT INTO property VALUES( $pr )"); } } elsif($MODE eq "ps"){ foreach(1..500){ my $ownerid = int( rand(1001 ) ); my $ps = &generate_photoset($ownerid); $dbh->do("INSERT INTO photoset VALUES( $ps )"); } } $wl->close(); $dbh->disconnect(); sub generate_member { my ($index) = shift; my $name = $dbh->quote($sr->randregex('Name\d\d')); my $lastname = $dbh->quote($sr->randregex('Lastname\d\d')); my $city =$dbh->quote( $sr->randregex('City\d\d')); my $country = $dbh->quote($sr->randregex('[A-Z]{3}')); my $email = $dbh->quote("email".$index.'@gmail.com'); my $nick = $dbh->quote("nick".$index); my $pw = $dbh->quote($sr->randregex('[A-Z]{2}[a-z]{2}.[a-z]{2}\d')); return "NULL, $name,$lastname,$city,$country,$email,$nick,$pw"; } sub generate_property { my $ownerid =shift; my $elt = $location[ rand @location ]; my @vals =@{$location{$elt}}; my $sub = $vals[rand @vals]; my $status = $status[ rand @status]; my $type = $type[ rand @type]; my $location = $dbh->quote($elt); my $sublocation = $dbh->quote( $sub); my $desc = $dbh->quote($sr->randregex('[A-Z]{20}')); my $type = $dbh->quote($type); my $price = $dbh->quote($sr->randregex('[1-5][0-9]0')."K GBP"); my $status = $dbh->quote($status); return "NULL, $ownerid,$location,$sublocation,$desc,$type,$price,$status"; } sub generate_photoset { my $ownerid = shift; my @pic = $wl->get_words(1); my $keywords = $dbh->quote(join(',',$wl->get_words(5))); my $desc = $dbh->quote(join(' ', $wl->get_words(6))); my $date = $dbh->quote(rand_date( min => '2007-01-01' )); my $path = $dbh->quote("/some/path/$pic[0].jpg"); return "NULL, $keywords,$desc,$date,$path, $ownerid"; } sub generate_foreign_ids { my $random = int( rand(1001 ) ); my $photoset; my $property; if($random%12 == 0 || $random == 0){ $photoset = 0; } else { $photoset = $random; } $random = int( rand(1001 ) ); if($random%16 ==0 || $random%10 == 0 || $random%9 == 0){ $property = 0; } else{ $property = $random; } return $property,$photoset; }