Revision [15088]

This is an old revision of BookmarkManagerImportScripts made by BrianKoontz on 2006-08-08 15:53:25.

 

BookmarkManager Import Scripts


A collection of scripts to assist with importing bookmarks from other sources into BookmarkManager
 


de.lirio.us import



parseDelirious.pl file1.html file2.html file3.html > myLinks.txt


Change the $base_url, $wikiname, and $password global vars in importDelirious.pl, then run against the file created in the previous step:

importDelirious.pl myLinks.txt


parseDelirious.pl
#! /usr/bin/perl
#
# $Id: parseDelirious.pl,v 1.2 2006/05/30 03:27:21 brian Exp brian $
#
# parseDelirious.pl - Parses a de.lirio.us screen dump (as saved by
# Firefox)
#
#####################################################################
require HTML::TreeBuilder;

foreach my $filename(@ARGV) {
    my $tree = HTML::TreeBuilder->new;
    $tree->parse_file($filename);
    $tree->elementify();
    @nodes = $tree->look_down("class","xfolkentry");
    foreach $node(@nodes) {
        $_ = $node->look_down("class","uri");
        $link = $_->extract_links();
        $title = $link->[0]->[1]->as_text();
        print "Title: $title\n";
        print "URI: $link->[0]->[0]\n";

        # Get description, if any
        $_=$node->look_down("class","extended");
        print "Desc: ";
        if($_) {
            $desc = $_->as_text();
            print "$desc";
        }
        print "\n";

        # A de.lirio.us export quirk prevents some tags from
        # displaying; default these to "@private" for later review
        @_ = $node->look_down("class","tag");
        print "Tags: ";
        if($#_ < 0) {
            print "\@private";
        }
        foreach $tagnode(@_) {
            $link = $tagnode->extract_links();
            $tag = $link->[0]->[1]->as_text();
            print "$tag ";
        }
        print "\n\n\n";
    }
    $tree = $tree->delete;
}


importDelirious.pl
#! /usr/bin/perl
#
# $Id: importDelirious.pl,v 1.3 2006/05/31 04:43:19 brian Exp brian $
#
# importDelirious.pl -- Imports file created by parseDelirious.pl
#
# Usage: importDelirious.pl exportFile
#
#####################################################################

require LWP::UserAgent;
require HTTP::Cookies;

###Global###
$base_url = "http://some.url.com/wiki/";
$bookmark_page = "Bookmarks";
$wikiname = "YourName";
$password = "yourpassword";

$ua = LWP::UserAgent->new;
$cookie_jar = HTTP::Cookies->new(file => "lwpcookies.txt",
                                   autosave => 1);
$ua->cookie_jar($cookie_jar);

# Login
$login_url = $base_url."wikka.php?wakka=UserSettings";
my $req = HTTP::Request->new(POST=>"$login_url");
$req->content_type('application/x-www-form-urlencoded');
$req->content("name=$wikiname&password=$password&action=login&wakka=UserSettings");
my $res = $ua->request($req);
$cookie_jar->extract_cookies($res);

# Import
open(IN, "<$ARGV[0]") || die "Can't open $ARGV[0] for reading!";
# Set autoflush so progress is displayed
my $oldfh = select(STDOUT); $| = 1; select($oldfh);
print "Importing...";
while(<IN>) {
    print ".";
    next until /Title: /;
    chomp;
    $title = (split(": ",$_))[1];
    $_ = <IN>;
    chomp;
    $uri = (split(": ",$_))[1];
    $_ = <IN>;
    chomp;
    $desc = (split(": ",$_))[1];
    $_ = <IN>;
    chomp;
    $tags = (split(": ",$_))[1];
    $add_url = $base_url."wikka.php?wakka=".$bookmark_page."&action=add";
    $req = HTTP::Request->new(POST=>"$add_url");
    $req->content_type('application/x-www-form-urlencoded');
    $req->content("title=$title&uri=$uri&desc=$desc&tags=$tags");
    $ua->request($req);
}
print "done!\n";
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki