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