# Convert tables to wiki pages # Author: Jared Freeman (freeman@aptima.com) # Usage: # Before running, set items in "Set Before Running" below # Configure tab-delimited entry table format thus: # Row1 (col headings) = wiki metafield names # Row2..n = data # Example input table: #MetaA MetaB MetaC #Acat Bcat Ccat #Adog Bdog Cdog # Limitations # Does not handle metafield attributes # Header is in-line and not selectable from commandline # File name and start number must be set manually (not yet command line) ##################### Header Library ############################# # Article header $ARTICLEHEADER = q(%META:TOPICINFO{author="JaredFreeman" date="1142483756" format="1.1" version="1.1"}% %META:TOPICPARENT{name="ArticlesTable"}% %META:FORM{name="ArticlePublicationForm"}% ); # Book/Video/Journal/MarketReport header $BOOKHEADER = q(%META:TOPICINFO{author="JaredFreeman" date="1142007504" format="1.1" version="1.2"}% %META:TOPICPARENT{name="LibraryPortal"}% %META:FORM{name="LibraryPublicationForm"}% ); ################################################################## ##################### Set Before Running ############################# $FILENAME="Publication"; $FILENUMBER=100; $FILETYPE=".txt"; $HEADER = $BOOKHEADER; ################################################################## print STDERR "For heavens sake test one of these output files in your twiki before dumping in the load."; while (<>) { s/\n//; next if (/^\s*$/); # If $REC == 0, these are metafield names. Grab & count if ($REC++ == 0) { @METAFIELDS = split(/\t/); $FIELDCT = $#METAFIELDS+1; } # Else ($REC > 0), these are data. Grab & print else { @DATAFIELDS = split(/\t/); # Enter solution here to output to unique file: Publication### # Compile new file name $FILE = $FILENAME.$FILENUMBER.$FILETYPE; $FILENUMBER++; # Open, write, and close file # Meanwhile, print a line to delimit files print "\n$FILE ##################################################################\n"; open(OUTFILE,">$FILE"); print OUTFILE $HEADER; for ($i=0; $i<$FIELDCT; $i++) { print OUTFILE q(%META:FIELD{name="); print OUTFILE "$METAFIELDS[$i]"; print OUTFILE q(" attributes="" title="); print OUTFILE "$METAFIELDS[$i]"; print OUTFILE q(" value="); print OUTFILE "$DATAFIELDS[$i]"; print OUTFILE q("}%); print OUTFILE "\n"; } close OUTFILE; } } # Sample record to match #%META:TOPICINFO{author="StacyLovell" date="1142007504" format="1.1" version="1.2"}% #%META:TOPICPARENT{name="LibraryPortal"}% # #%META:FORM{name="LibraryPublicationForm"}% #%META:FIELD{name="Reference" attributes="" title="Reference" value="Chapanis, Alphonse (1990). The Chapanis Chronicles. Santa Barbara, CA: AegeanPublishing? Company"}% #%META:FIELD{name="Medium" attributes="" title="Medium" value="book"}% #%META:FIELD{name="Location" attributes="" title="Location" value="MA library"}% #%META:FIELD{name="Notes" attributes="" title="Notes" value="Accession: AP-B-0004; Vol: Vol: ?; Series: Series: ?; Series Ed: Series Ed: ?; Pg: Pg: ?; ISBN: ISBN: 0-9636178-9-3 ;"}% #%META:FIELD{name="Topic_Relation" attributes="" title="Topic_Relation" value=""}% #%META:FIELD{name="Keywords" attributes="" title="Keywords" value=""}%