add core.HistoryDays for variable history kept

This commit is contained in:
nytpu
2021-05-19 08:00:21 -06:00
parent ac86835f6d
commit f9d8872260
4 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ func main() {
// make sure it exists so we can start working with files in it
os.MkdirAll(dataPath, os.ModePerm)
err := core.Init(dataPath, localizer)
err := core.Init(dataPath, localizer, 0)
if err != nil {
fmt.Fprintf(os.Stderr, core.TranslateStringLocalizer(
localizer, "%s\n",
+7 -1
View File
@@ -19,6 +19,7 @@ import (
"os"
"path/filepath"
"sync"
"time"
"golang.nytpu.com/comitium/localizations"
)
@@ -40,11 +41,14 @@ var (
// Timeout for requests
var Timeout int
// Number of days of history to keep
var HistoryDays time.Time
var Localizer *localizations.Localizer
// have to do this instead of the automatically called init() because
// initialization stuff requires parsing of command line args first
func Init(dataPath string, localizer *localizations.Localizer) error {
func Init(dataPath string, localizer *localizations.Localizer, days int) error {
Localizer = localizer
// initialize comitium.json & data maps
@@ -98,6 +102,8 @@ func Init(dataPath string, localizer *localizations.Localizer) error {
}
Footer = fmt.Sprintf("\n\n%s", footer)
HistoryDays = time.Now().AddDate(0, 0, -days)
Timeout = 10
return nil
+1 -1
View File
@@ -83,7 +83,7 @@ func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error) {
item.Link = v.Link
// don't insert if older than 1 year
if item.Published.After(time.Now().AddDate(-1, 0, 0)) {
if item.Published.After(HistoryDays) {
new.Items = append(new.Items, item)
}
}
+1 -1
View File
@@ -98,7 +98,7 @@ func geminiFeed(data *core.FullData, remote string, title string) error {
item.Link = link.String()
// don't insert if older than 1 year
if item.Published.After(time.Now().AddDate(-1, 0, 0)) {
if item.Published.After(core.HistoryDays) {
feed.Items = append(feed.Items, item)
}
}