From e64aa5ac633997c9c6cf10608750d01856758e8e Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Fri, 3 Aug 2018 13:33:57 +0200 Subject: [PATCH] Changet getArticles to save timestamp after every updated article as I learned there are feeds which have the articles in wrong order (looking at you spiegel.de). --- getarticles.go | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/getarticles.go b/getarticles.go index f8d4949..67b5b1d 100644 --- a/getarticles.go +++ b/getarticles.go @@ -168,29 +168,27 @@ func getArticles(feedURL string, max int) (string, error) { continue } - if i == 0 { - last = updateTime - lastUpdate.LastChange = updateTime.Format(time.RFC3339) + last = updateTime + lastUpdate.LastChange = updateTime.Format(time.RFC3339) - // Remove file with cached timestamp and create it - // again with updated timestamp. - // ToDo: Replace timestamp without deleting. - err = os.Remove(cacheFile) - if err != nil { - log.Fatal("Error: ", err) - } + // Remove file with cached timestamp and create it + // again with updated timestamp. + // ToDo: Replace timestamp without deleting. + err = os.Remove(cacheFile) + if err != nil { + log.Fatal("Error: ", err) + } - file, err = os.Create(cacheFile) - if err != nil { - log.Fatal("Error: ", err) - } - defer file.Close() + file, err = os.Create(cacheFile) + if err != nil { + log.Fatal("Error: ", err) + } + defer file.Close() - lastUpdateJSON, _ := json.MarshalIndent(lastUpdate, "", " ") - _, err = file.Write(lastUpdateJSON) - if err != nil { - log.Fatal("Error: ", err) - } + lastUpdateJSON, _ := json.MarshalIndent(lastUpdate, "", " ") + _, err = file.Write(lastUpdateJSON) + if err != nil { + log.Fatal("Error: ", err) } // Remove redirects and tracking parameters from URL.