source: bookmarks/trunk/import @ 112

Last change on this file since 112 was 2, checked in by peter, 13 years ago

Added exisiting bookmarks project files

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/perl -w
2use strict;
3
4use XML::XPath;
5use DBI;
6use YAML;
7use Time::Local;
8
9my $xpath = XML::XPath->new(filename => 'delicious.xml');
10
11my $nodeset = $xpath->find('/posts/post');
12
13binmode(STDOUT, ":utf8");
14
15use Bookmarks;
16my $bookmarks = Bookmarks->new({
17    dbh => DBI->connect("dbi:SQLite:dbname=bookmarks.db", "", "", { RaiseError => 1 })
18});
19
20foreach my $node ($nodeset->get_nodelist) {
21    my $timestamp = $node->getAttribute('time');
22    my ($year, $month, $day, $hour, $minute, $second) = ($timestamp =~ /^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/);
23    my $ctime = timegm($second, $minute, $hour, $day, $month - 1, $year);
24    my %bookmark = (
25        uri   => $node->getAttribute('href'),
26        title => sanitize($node->getAttribute('description')),
27        tags  => [ split ' ', $node->getAttribute('tag') ],
28        ctime => $ctime,
29    );
30    print Dump(\%bookmark);
31    #TODO: UTF-8 issues
32    $bookmarks->add(\%bookmark);
33}
34
35
36# strip out Unicode control characters that are showing up in YouTube link titles
37sub sanitize {
38    my $string = shift;
39    $string =~ s/[\x{202a}\x{202c}\x{200f}]//g;
40    return $string;
41}
Note: See TracBrowser for help on using the repository browser.