#!/usr/bin/tclsh
package require tdom
package require tdbc::sqlite3
# prepare our sqlite database
tdbc::sqlite3::connection create db "feedly.db"
set statement [db prepare {drop table if exists mylist}]
$statement execute
$statement close
set statement [db prepare {create table mylist (title TEXT, xmlUrl TEXT, htmlUrl TEXT, PRIMARY KEY (title))}]
$statement execute
$statement close
# setup feedly opml file path
set filename "/home/danilo/Personal/feedly.opml"
# parse XML data
set doc [dom parse [tDOM::xmlReadFile $filename "UTF-8"]]
set root [$doc documentElement]
set nodeList [$root selectNodes /opml/body/outline/outline]
set title ""
set xmlUrl ""
set htmlUrl ""
set statement [db prepare {insert into mylist values(:title, :xmlUrl, :htmlUrl)}]
foreach node $nodeList {
if {[catch {set title [$node getAttribute title]}] != 0} {
set title ""
}
if {[catch {set xmlUrl [$node getAttribute xmlUrl]}] != 0} {
set xmlUrl ""
}
if {[catch {set htmlUrl [$node getAttribute htmlUrl]}] != 0} {
set htmlUrl ""
}
$statement execute
}
$statement close
db close
第二個則是讀出來確定有轉存成功:
#!/usr/bin/tclsh
package require tdbc::sqlite3
tdbc::sqlite3::connection create db "feedly.db"
set statement [db prepare {SELECT * FROM mylist}]
$statement foreach row {
puts "RSS title: [dict get $row title]"
puts "RSS xmlUrl: [dict get $row xmlUrl]"
puts "RSS htmlUrl: [dict get $row htmlUrl]"
}
$statement close
db close
沒有留言:
張貼留言