Initial commit, not functioning
This commit is contained in:
commit
de597f2f0d
3 changed files with 96 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.sqlite3
|
2
db.sql
Normal file
2
db.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
CREATE TABLE bookmarks (url text not null primary key);
|
||||
|
93
pocketarchive.go
Normal file
93
pocketarchive.go
Normal file
|
@ -0,0 +1,93 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func checkUrl(url string, db *sql.DB) bool {
|
||||
row := db.QueryRow(`SELECT COUNT(url) FROM bookmarks where URL="%s"`, url)
|
||||
|
||||
if row != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func addNewUrl(url string, db *sql.DB) sql.Row {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Launching Pocket Archive...")
|
||||
|
||||
fmt.Println("Getting archive data from Pocket...")
|
||||
|
||||
// Pull data from RSS feed.
|
||||
archiveUrl := "https://getpocket.com/users/amdavidson/feed/read"
|
||||
|
||||
resp, err := http.Get(archiveUrl)
|
||||
if err != nil {
|
||||
fmt.Println("Could not get archived urls")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
|
||||
// Make up some data structures into which we can put our feed.
|
||||
type Bookmark struct {
|
||||
// Required
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Guid string `xml:"guid"`
|
||||
// Optional
|
||||
PubDate string `xml:"pubDate"`
|
||||
Comments string `xml:"comments"`
|
||||
}
|
||||
|
||||
type Feed struct {
|
||||
XMLName xml.Name `xml:"rss"`
|
||||
Version string `xml:"version,attr"`
|
||||
// Required
|
||||
Title string `xml:"channel>title"`
|
||||
Link string `xml:"channel>link"`
|
||||
Description string `xml:"channel>description"`
|
||||
// Optional
|
||||
PubDate string `xml:"channel>pubDate"`
|
||||
BookmarkList []Bookmark `xml:"channel>item"`
|
||||
}
|
||||
|
||||
// Parse the feed
|
||||
f := Feed{}
|
||||
err = xml.Unmarshal(body, &f)
|
||||
if err != nil {
|
||||
fmt.Println("Could not parse feed")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Put data in sqlite3
|
||||
db, err := sql.Open("sqlite3", "./bookmarks.sqlite3")
|
||||
if err != nil {
|
||||
fmt.Println("Could not open database")
|
||||
panic(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
for _, bookmark := range f.BookmarkList {
|
||||
if checkUrl(bookmark.Guid, db) == true {
|
||||
fmt.Println("New bookmark url %s", bookmark.Guid)
|
||||
} else {
|
||||
fmt.Println("Already know about %s", bookmark.Guid)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Pocket Archive exiting.")
|
||||
|
||||
}
|
Loading…
Reference in a new issue