Last change
on this file since 126 was
2,
checked in by peter, 13 years ago
|
Added exisiting bookmarks project files
|
-
Property svn:executable set to
*
|
File size:
1.1 KB
|
Rev | Line | |
---|
[2] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | |
---|
| 4 | use XML::XPath; |
---|
| 5 | use DBI; |
---|
| 6 | use YAML; |
---|
| 7 | use Time::Local; |
---|
| 8 | |
---|
| 9 | my $xpath = XML::XPath->new(filename => 'delicious.xml'); |
---|
| 10 | |
---|
| 11 | my $nodeset = $xpath->find('/posts/post'); |
---|
| 12 | |
---|
| 13 | binmode(STDOUT, ":utf8"); |
---|
| 14 | |
---|
| 15 | use Bookmarks; |
---|
| 16 | my $bookmarks = Bookmarks->new({ |
---|
| 17 | dbh => DBI->connect("dbi:SQLite:dbname=bookmarks.db", "", "", { RaiseError => 1 }) |
---|
| 18 | }); |
---|
| 19 | |
---|
| 20 | foreach 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 |
---|
| 37 | sub 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.