Changeset 1424
- Timestamp:
- 03/16/07 10:17:16 (2 years ago)
- Files:
-
- feedmelinks/bin/import-bookmarks.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
feedmelinks/bin/import-bookmarks.pl
r1382 r1424 2 2 use lib "/home/fml/public_html/lib"; 3 3 use FeedMeLinks::Environment; 4 #use strict; 5 6 my ($debug, $link, $tag, @tags, @links, @folks, $url, $hideGarbage, $dd, $glc, $mandatory_tag, $path, $filename, $bin, $format, $cmd, $depth, $folksPath, $lastDepth, $lastFolder, $description); 4 7 5 8 $glc = 0; 6 7 my ($link, $tag, @tags, @links, @folks, $hideGarbage, $dd, $glc, $mandatory_tag, $path, $bin, $format); 9 $debug = 0; 8 10 9 11 $link = $tag = undef; 10 $hideGarbage = true;12 $hideGarbage = 1; 11 13 $glc = 0; 12 14 push @folks, "ROOT"; … … 18 20 # extract the user name from the file path (this practice oculd be considered a bit shady...) 19 21 $path = $filename = $ARGV[0]; 20 $parser = $ARGV[1];21 $link_xslt = $ARGV[2];22 $tag_xslt = $ARGV[3];22 my $parser = $ARGV[1]; 23 my $link_xslt = $ARGV[2]; 24 my $tag_xslt = $ARGV[3]; 23 25 $path =~ s:\/([^/]+)$::; #strip filename 24 26 $bin ="/home/fml/public_html/bin"; 25 27 26 $success_code = "";27 28 $converted = "/tmp/import-" . int(rand(1000));28 my $success_code = ""; 29 30 my $converted = "/tmp/import-" . int(rand(1000)); 29 31 # one of: delicious-hybrid, netscape, delicious-API 30 32 $format = detect_bookmarks_format( $bin, $filename ); 31 if( $format == "delicious-hybrid" ) { 32 print "converting from hybrid format:\n"; 33 34 print "format: |$format|\n" if( $debug ); 35 36 if( $format eq "delicious-hybrid" ) { 37 print "converting from hybrid format:\n" if( $debug ); 33 38 $cmd = "$bin/hybrid-to-xml.pl $filename > $converted"; 34 39 print "cmd: $cmd\n"; … … 36 41 $filename = $converted; 37 42 #print "new converted xml output is in $filename\n"; 38 $out = `cat $filename`;39 print "$filename contains: \n $out\n\n";43 my $out = `cat $filename`; 44 print "$filename contains: \n</code><form><textarea rows='40' cols='150'>$out</textarea></form><code>\n\n" if( $debug ); 40 45 $success_code = "converted from hybrid to stock xml"; 46 47 #magic format swap-eroo now that we've converted 48 $format = "delicious-API"; 41 49 } 42 50 43 51 while( <> ) { 44 $line = $_; 45 46 # EITHER THE FUCKING PERL REGEX SYNTAX CHANGED OR RP HAS A BROKEN PERL 47 if( $line =~ m/xml version/ ) { 48 #<?xml version='1.0' standalone='yes'?> 49 52 my $line = $_; 53 54 if( $format eq "delicious-API" ) { 55 50 56 $cmd = "xsltproc $link_xslt $filename > $path/LINKS.RAW\n"; 51 print " $cmd\n";52 $out = `$cmd`;57 print "cmd:<br>$cmd\n" if( $debug ); 58 my $out = `$cmd`; 53 59 print "cmd output was: $out\n"; 54 60 … … 143 149 my $cmd = "$bin/detect-bookmarks-file-format.sh $filename"; 144 150 my $out = `$cmd`; 151 chomp( $out ); 145 152 return $out; 146 153 } … … 158 165 159 166 sub get_folks_path() { 160 $folksPath = "";167 my $folksPath = ""; 161 168 foreach( @folks ) { 162 $f = $_;169 my $f = $_; 163 170 $folksPath = "$folksPath / $f"; 164 171 } … … 168 175 169 176 sub strip_first { 170 $fp = $_[0];177 my $fp = $_[0]; 171 178 $fp =~ s/ \/ /$dd/g; 172 179 $fp =~ s/^ROOT/$mandatory_tag/; … … 175 182 176 183 sub add_pending_link_or_tag() { 184 my $s; 177 185 if( $link ) { 178 $tag_list = strip_first( $folksPath);186 my $tag_list = strip_first( $folksPath); 179 187 $s = $url . $dd . $link . $dd . $tag_list; 180 #p( $s );181 188 push @links, $s; 182 183 #p( "INSERT INTO links VALUES( NULL, '$url', $link, NULL, NULL, NEED_USER_HERE_TBD, NULL, 1 );" );184 185 189 $link = $description = undef; 186 190 } elsif( $tag ) { 187 191 $s = $tag; 188 #p( $s );189 192 push @tags, $s; 190 193 $tag = undef;