[Bast-commits] r8170 - ironman/IronMan-Web/script
iain at dev.catalyst.perl.org
iain at dev.catalyst.perl.org
Thu Dec 24 12:32:12 GMT 2009
Author: iain
Date: 2009-12-24 12:32:12 +0000 (Thu, 24 Dec 2009)
New Revision: 8170
Modified:
ironman/IronMan-Web/script/import_csv.pl
Log:
accept args for csv_path and csv_db
Modified: ironman/IronMan-Web/script/import_csv.pl
===================================================================
--- ironman/IronMan-Web/script/import_csv.pl 2009-12-24 12:02:52 UTC (rev 8169)
+++ ironman/IronMan-Web/script/import_csv.pl 2009-12-24 12:32:12 UTC (rev 8170)
@@ -2,31 +2,51 @@
use strict;
use warnings;
+use Getopt::Long;
+use Pod::Usage;
+
+
use utf8 ();
-=head1 import_csv.pl
+=head1 SYNOPSIS
-This script is a one hit import from the "old" csv file to the new feed db.
+ import_csv.pl import_csv.pl --csv_path=/home/iain/Projects/ironman/csv --db_path=/home/iain/Projects/ironman/subscriptions.db
+This script is a one hit import from the old csv file to the new feed db.
+
+pass the csv_path and db_path e.g.
+
+ import_csv.pl --csv_path=/home/iain/Projects/ironman/csv --db_path=/home/iain/Projects/ironman/subscriptions.db
+
It is safe to run multiple times on the same data.
-All you need to do is fill in the correct paths to your csv files and subscriptions.db
-
A file called problems.txt will be generated with .... problems, usually missing dates.
=cut
+
use Data::Dumper;
use IronMan::Schema;
use Text::CSV_XS;
use DateTime::Format::HTTP;
-# UPDATE THESE PATHS #
-#die "UPDATE YOUR PATHS AND REMOVE THIS LINE";
-my @files = </home/iain/Projects/ironman/csv/*>;
-my $schema = IronMan::Schema->connect('dbi:SQLite:/home/iain/Projects/ironman/subscriptions.db');
+my ( $csv_path, $db_path );
+GetOptions(
+ 'csv_path=s' => \$csv_path,
+ 'db_path=s' => \$db_path,
+) or die pod2usage;
-print scalar(@files),"\n";
+unless($csv_path && $db_path) {
+ print "bugger";
+ die pod2usage;
+}
+$csv_path .= '/*';
+
+my @files = glob($csv_path);
+my $schema = IronMan::Schema->connect("dbi:SQLite:$db_path");
+
+print scalar(@files)," files found\n";
+
binmode(STDOUT, ":utf8");
open(PROBLEMS, '>', 'problems.txt') || die "cant open problems file $!";
More information about the Bast-commits
mailing list