From 345887f3c8319c6dd91f20cd75615fd5c9fcf460 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Thu, 7 May 2020 00:13:34 +0200 Subject: Unified publishedDate and updatedDate into one (just as the old feed2imap...) --- CHANGELOG.md | 1 + internal/feed/cache_v1.go | 31 +++++++++++++------------------ internal/feed/item.go | 15 +++++++++++++++ internal/feed/mail.go | 4 ++-- internal/feed/template/feed.tpl.go | 2 +- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7a5636..1108509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Default for `min-frequency` is now 0 instead of 1. +- Fixed date parsing from feed. _Changes cache format!_ ## [0.1.1] - 2020-05-04 diff --git a/internal/feed/cache_v1.go b/internal/feed/cache_v1.go index e2562c3..18b12c3 100644 --- a/internal/feed/cache_v1.go +++ b/internal/feed/cache_v1.go @@ -41,14 +41,13 @@ type cachedFeed struct { type itemHash [sha256.Size]byte type cachedItem struct { - Guid string - Title string - Link string - PublishedDate time.Time - UpdatedDate time.Time - UpdatedCache time.Time - Hash itemHash - ID uuid.UUID + Guid string + Title string + Link string + Date time.Time + UpdatedCache time.Time + Hash itemHash + ID uuid.UUID } func (item cachedItem) String() string { @@ -56,9 +55,8 @@ func (item cachedItem) String() string { Title: %q Guid: %q Link: %q - Published: %s - Updated: %s -}`, item.Title, item.Guid, item.Link, util.TimeFormat(item.PublishedDate), util.TimeFormat(item.UpdatedDate)) + Date: %s +}`, item.Title, item.Guid, item.Link, util.TimeFormat(item.Date)) } func (cf *cachedFeed) Checked(withFailure bool) { @@ -159,11 +157,8 @@ func (item *item) newCachedItem() cachedItem { ci.ID = item.itemId ci.Title = item.Item.Title ci.Link = item.Item.Link - if item.Item.PublishedParsed != nil { - ci.PublishedDate = *item.Item.PublishedParsed - } - if item.Item.UpdatedParsed != nil && !item.Item.UpdatedParsed.Equal(ci.PublishedDate) { - ci.UpdatedDate = *item.Item.UpdatedParsed + if item.DateParsed() != nil { + ci.Date = *item.DateParsed() } ci.Guid = item.Item.GUID @@ -176,7 +171,7 @@ func (item *item) newCachedItem() cachedItem { func (item *cachedItem) similarTo(other *cachedItem, ignoreHash bool) bool { return other.Title == item.Title && other.Link == item.Link && - other.PublishedDate.Equal(item.PublishedDate) && + other.Date.Equal(item.Date) && (ignoreHash || other.Hash == item.Hash) } @@ -215,7 +210,7 @@ func (cf *cachedFeed) filterItems(items []item, ignoreHash, alwaysNew bool) []it CACHE_ITEMS: for ci, item := range cacheItems { log.Debugf("Now checking %s", ci) - if cf.LastCheck.IsZero() || ci.PublishedDate.After(cf.LastCheck) { + if cf.LastCheck.IsZero() || ci.Date.After(cf.LastCheck) { log.Debug("Newer than last check, including.") item.addReason("time") diff --git a/internal/feed/item.go b/internal/feed/item.go index bbf7668..8b747fb 100644 --- a/internal/feed/item.go +++ b/internal/feed/item.go @@ -3,6 +3,7 @@ package feed import ( "encoding/base64" "fmt" + "time" "github.com/google/uuid" "github.com/mmcdole/gofeed" @@ -27,6 +28,20 @@ type item struct { itemId uuid.UUID } +func (item *item) DateParsed() *time.Time { + if item.UpdatedParsed == nil || item.UpdatedParsed.IsZero() { + return item.PublishedParsed + } + return item.UpdatedParsed +} + +func (item *item) Date() string { + if item.Updated == "" { + return item.Published + } + return item.Updated +} + // Creator returns the name of the creating author. func (item *item) Creator() string { if item.Author != nil { diff --git a/internal/feed/mail.go b/internal/feed/mail.go index 190e1f2..a763ef8 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -63,7 +63,7 @@ func (item *item) buildHeader() message.Header { h.Set("Message-Id", item.messageId()) { // date - date := item.PublishedParsed + date := item.DateParsed() if date == nil { now := time.Now() date = &now @@ -73,7 +73,7 @@ func (item *item) buildHeader() message.Header { { // subject subject := item.Title if subject == "" { - subject = item.Published + subject = item.Date() } if subject == "" { subject = item.Link diff --git a/internal/feed/template/feed.tpl.go b/internal/feed/template/feed.tpl.go index 2f51bbe..c3aede5 100644 --- a/internal/feed/template/feed.tpl.go +++ b/internal/feed/template/feed.tpl.go @@ -64,7 +64,7 @@ const feedTpl = `{{- /*gotype:github.com/Necoro/feed2imap-go/internal/feed.feedi {{end}}
- {{template "bottomLine" (dict "descr" "Date:" "content" .Published)}} + {{template "bottomLine" (dict "descr" "Date:" "content" .Date)}} {{template "bottomLine" (dict "descr" "Author:" "content" .Creator)}} {{template "bottomLine" (dict "descr" "Filed under:" "content" (join ", " .Categories))}} {{with .FeedLink}} -- cgit v1.2.3-70-g09d2
2010-04-19Remove unused pythonic eix parser implementationRené 'Necoro' Neumann1-416/+0
2010-04-19Connect the accels from the menu.René 'Necoro' Neumann1-12/+16
2010-04-19Replace 'Portage Warning' by 'External Warning'René 'Necoro' Neumann1-1/+1
2010-04-17Updated italian translation. Thx to PonsiRené 'Necoro' Neumann1-314/+369
2010-04-16Fix gtk deprecation warningRené 'Necoro' Neumann1-1/+1
2010-04-16TypoRené 'Necoro' Neumann2-3/+3
2010-04-16Do not allow portage's sqlite backend for the moment ... bug #564292René 'Necoro' Neumann2-16/+25
2010-04-15Better sorting of the database types in the preferences.René 'Necoro' Neumann2-6/+6
2010-04-15Add notify-python dependency for the version checkerRené 'Necoro' Neumann1-1/+1
2010-04-15Make the database type choice an info messageRené 'Necoro' Neumann2-7/+13
2010-04-15Renamed es_ES to esRené 'Necoro' Neumann1-0/+0
2010-04-15Fixed dependancy of the new_version plugin from "dev-util/git" to "dev-vcs/gi...Clement Bourgeois1-1/+1
2010-04-14Make some useless info messages being debug statementsRené 'Necoro' Neumann2-34/+17
2010-04-14Improve the C modulesRené 'Necoro' Neumann3-37/+52
2010-04-14Small modifications made to the French translation (typos, grammar).Clement Bourgeois1-69/+69
2010-04-14Fixed the unicode support and stuff ... and also made eix faster :)René 'Necoro' Neumann1-20/+22
2010-04-14Disable debug messages by defaultRené 'Necoro' Neumann1-1/+1
2010-04-13Better eix error inheritance and handlingRené 'Necoro' Neumann1-2/+9
2010-04-13Fix the handling of FilterSets. Fixes bug #558887.René 'Necoro' Neumann2-56/+64
2010-04-12Updated newsRené 'Necoro' Neumann1-0/+1
2010-04-13Added my name to translators list.Clement Bourgeois1-0/+1