5 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs dbh);
11 &untaint_argv; #what it sounds like (eww)
14 my $user = shift or die &usage;
15 my $dbh = adminsuidsetup $user;
17 my $content = get("http://www.census.gov/population/www/metroareas/lists/2009/List1.txt");
18 my @content = split(/\n/,$content);
20 my $sql = 'insert into msa (msanum, description) values ';
22 foreach my $row ( @content ) {
23 next unless $row =~ /^([0-9]{5})\s+([A-Za-z, \-]{5,80}) .{3}ropolitan Statistical Area/;
24 push @sql, "( $1, '$2')";
26 $sql .= join(',',@sql);
28 my $sth = $dbh->prepare('delete from msa');
29 $sth->execute or die $sth->errstr;
31 $sth = $dbh->prepare($sql);
32 $sth->execute or die $sth->errstr;
41 foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
42 #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
44 $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
50 die "Usage:\n freeside-msa-import user \n";
59 freeside-msa-import - Pull MSA data from census.gov and insert into MSA table
63 freeside-msa-import user
67 user - name of an internal Freeside user