42 lines
839 B
Go
42 lines
839 B
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/xml"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
func pullPocket(db *sql.DB) {
|
|
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)
|
|
|
|
// Parse the feed
|
|
f := Feed{}
|
|
err = xml.Unmarshal(body, &f)
|
|
if err != nil {
|
|
fmt.Println("Could not parse feed")
|
|
panic(err)
|
|
}
|
|
|
|
for _, bookmark := range f.BookmarkList {
|
|
if bookmarkExists(bookmark.GUID, db) == false {
|
|
fmt.Printf("New bookmark url %s\n", bookmark.GUID)
|
|
ingestURL(bookmark.GUID, db)
|
|
} else {
|
|
fmt.Printf("Already know about %s\n", bookmark.GUID)
|
|
}
|
|
}
|
|
}
|