diff options
author | Adam Mathes <adam@trenchant.org> | 2018-04-27 15:52:00 -0700 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2018-04-27 15:52:00 -0700 |
commit | 5068ca5c0d88694ec1c25dce81c747d5cfa6b54e (patch) | |
tree | 644bfb34b8525dbb7077ea5b2a3f5a1e24512b82 /models | |
parent | b773d3b1fa1ca4e01b100eb5e89b88b8347740ce (diff) | |
download | neko-5068ca5c0d88694ec1c25dce81c747d5cfa6b54e.tar.gz neko-5068ca5c0d88694ec1c25dce81c747d5cfa6b54e.tar.bz2 neko-5068ca5c0d88694ec1c25dce81c747d5cfa6b54e.zip |
separator for scrape
Diffstat (limited to 'models')
-rw-r--r-- | models/item/item.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/models/item/item.go b/models/item/item.go index 8d1d473..f70bba1 100644 --- a/models/item/item.go +++ b/models/item/item.go @@ -81,7 +81,13 @@ func filterPolicy() *bluemonday.Policy { return p } +func ItemById(id int64) *Item { + items, _ := Filter(0, 0, "", false, false, id) + return items[0] +} + func (i *Item) GetFullContent() { + fmt.Printf("fetching from %s\n", i.Url) g := goose.New() article, err := g.ExtractFromURL(i.Url) if err != nil { @@ -105,9 +111,8 @@ func (i *Item) GetFullContent() { } p := filterPolicy() - md = p.Sanitize(ht) - - img = article.TopImage + i.FullContent = p.Sanitize(ht) + i.HeaderImage = article.TopImage _, err = models.DB.Exec(`UPDATE item SET full_content=?, header_image=? @@ -117,7 +122,7 @@ func (i *Item) GetFullContent() { } } -func Filter(max_id int64, feed_id int64, category string, unread_only bool, starred_only bool) ([]*Item, error) { +func Filter(max_id int64, feed_id int64, category string, unread_only bool, starred_only bool, item_id int64) ([]*Item, error) { var args []interface{} @@ -148,13 +153,20 @@ func Filter(max_id int64, feed_id int64, category string, unread_only bool, star query = query + " AND item.read_state=0 " } + if item_id != 0 { + query = query + " AND item.id=? " + args = append(args, item_id) + } + + // this is kind of dumb, but to keep the logic the same + // we kludge it this way for a "by id" select if starred_only { query = query + " AND item.starred=1 " } query = query + "ORDER BY item.id DESC LIMIT 15" - // log.Println(query) - // log.Println(args...) + // log.Println(query) + // log.Println(args...) rows, err := models.DB.Query(query, args...) if err != nil { |