Skip to content

Instantly share code, notes, and snippets.

@sparr
Last active December 26, 2015 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sparr/7143455 to your computer and use it in GitHub Desktop.
Save sparr/7143455 to your computer and use it in GitHub Desktop.
convert sched.org vendor list exported csv to guidebook exhibitor list importable csv
#!/usr/bin/perl
use Text::CSV;
my @rows;
my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
or die "Cannot use CSV: ".Text::CSV->error_diag ();
# discard metadata non-rows
<>; # Sched: [nameoflist],Downloaded on 1999-09-09 9:09:09 pm,,,,,,,,,,
<>; # When Complete ⇒ [Upload Here],,,,,,,,,,,
<>; # version 2.5,,,,,,,,,,,
<>; # Need Help? ⇒ [View Here],,,,,,,,,,,
# discard header row
<>; # NAME (Required),EMAIL ADDRESS (Optional),PASSWORD (Optional),BOOTH (Optional),BIO/DESCRIPTION (Optional),RELATED WEBSITE (Optional),IMAGE (Optional),,,,,
# read stdin or the input file, populate the rows array with data massaged to Guidebooks' standards
while ( <> ) {
# convert the input line into an array of fields
$csv->parse($_);
my @row = $csv->fields();
#TODO: this prefix should be configurable
my $location = ($row[3])?("Room " . $row[3]):"";
push @rows, [
# garbage column
"Imported Row",
# guidebook.Name = sched.Name
$row[0],
# guidebook.Subtitle = sched.Location
$location,
# guidebook.Description = sched.Description + sched.Website
$row[4] . (($row[4] && $row[5])?"\n":"") . $row[5],
# guidebook.Location = sched.Location
$location
];
}
# confirm that we reached the end of the file, probably redundant with while(<>)
$csv->eof or $csv->error_diag();
$csv->eol ("\n");
# preserve non-ascii characters
binmode STDOUT, ':utf8';
# header required by Guidebook import
$csv->print (STDOUT, [
"Don't change any of the headers!",
"Name",
"Sub-Title (i.e. Location, Table/Booth, or Title/Sponsorship Level)",
"Description (Optional)",
"Location/Room"
]);
# output all the csv rows
$csv->print (STDOUT, $_) for @rows;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment