cleanup
This commit is contained in:
parent
40cbaadf83
commit
92be9919e3
2
TODO.md
2
TODO.md
@ -26,9 +26,9 @@
|
||||
* Podcasts
|
||||
|
||||
## 1.0
|
||||
* ✓ concurrent processing
|
||||
* Review all errors wrapped properly
|
||||
* Change log from byte to string
|
||||
* concurrent processing
|
||||
* Config validation
|
||||
* Cron spec
|
||||
* Name - No spaces
|
||||
|
35
app/db.go
35
app/db.go
@ -84,33 +84,36 @@ func (d *db) Filter(entries []parser.FeedEntry) ([]parser.FeedEntry, error) {
|
||||
}
|
||||
|
||||
func (d *db) Save(records []Record) error {
|
||||
if len(records) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(d.dbPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
f.Sync()
|
||||
f.Close()
|
||||
}()
|
||||
defer f.Close()
|
||||
|
||||
csvw := csv.NewWriter(f)
|
||||
if len(d.seenLinks) == 0 { //New file, write header
|
||||
defer csvw.Flush()
|
||||
|
||||
if d.IsNewFeed() {
|
||||
csvw.Write([]string{
|
||||
"Date",
|
||||
"Link",
|
||||
"Status",
|
||||
"Filter",
|
||||
"Content",
|
||||
/* 1 */ "Date",
|
||||
/* 2 */ "Link",
|
||||
/* 3 */ "Status",
|
||||
/* 4 */ "Filter",
|
||||
/* 5 */ "Content",
|
||||
})
|
||||
}
|
||||
for _, r := range records {
|
||||
csvw.Write([]string{
|
||||
r.Time.Format(TimeFormat),
|
||||
r.FeedEntry.Link,
|
||||
string(r.Status),
|
||||
r.Filter,
|
||||
fmt.Sprintf("<item>%s</item>", strings.ReplaceAll(r.FeedEntry.Content, "\n", " ")),
|
||||
/* 1 */ r.Time.Format(TimeFormat),
|
||||
/* 2 */ r.FeedEntry.Link,
|
||||
/* 3 */ string(r.Status),
|
||||
/* 4 */ r.Filter,
|
||||
/* 5 */ fmt.Sprintf("<item>%s</item>", strings.ReplaceAll(r.FeedEntry.Content, "\n", " ")),
|
||||
})
|
||||
}
|
||||
csvw.Flush()
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user