-
Notifications
You must be signed in to change notification settings - Fork 0
/
book2json
executable file
·43 lines (40 loc) · 989 Bytes
/
book2json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl
use Time::localtime;
sub toDate($);
# skip the header
my $headerFinished = 0;
while(! $headerFinished) {
$_ = <>;
$headerFinished = 1 if m#\<H1\>Bookmarks\<\/H1\>#i;
}
while(<>) {
chomp;
s/\r//;
s/ /\t/g;
s#<p/?>##ig;
s#(add_date|last_modified)="(\d+)"#sprintf("%s=\"%s\"", lc($1), toDate($2));#gie;
s#<dl>#list=[#ig;
s#</dl>#]#ig;
s#<a href="(.*)" add_date="(.*)">(.*)</a>#url="$1", add_date="$2", name="$3"#i;
s# ICON="[^"]*"##;
s#^(\s*)<DT><H3 ([^>]*)>(.*)</H3>#$i=$1;chop($i);sprintf("%s\n%s\n%s", "${i}{", "${1}title=\"${3}\",\n${1}$2");#ie;
s#<dt>(.*)#{ $1 },#ig;
s#\n(\s*)(add_date="[^"]*") (last_modified="[^"]*)#\n$1$2,\n$1$3#gi;
print "$_\n";
}
sub toDate($) {
my $timestamp = shift;
my $t = localtime($timestamp);
my @days = qw(Sun Mon Tue Wed Thu Fri Sat);
my $stamp = sprintf(
"%04d-%02d-%02d.%02d%02d.%02d (%s)",
1900+@{$t}[5],
1+@{$t}[4],
@{$t}[3],
@{$t}[2],
@{$t}[1],
@{$t}[0],
$days[@{$t}[6]]
);
return $stamp;
}