Init
This commit is contained in:
commit
310fcc6eb0
86 changed files with 10611 additions and 0 deletions
50
save.go
Normal file
50
save.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func loadNotifiedEntries() {
|
||||
file, err := os.Open(notifiedFilePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return
|
||||
}
|
||||
log.Fatalf("Error loading notified entries: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
err = json.NewDecoder(file).Decode(¬ifiedEntries)
|
||||
if err != nil {
|
||||
log.Fatalf("Error decoding notified entries: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func saveNotifiedEntry(entryNumber int) {
|
||||
notifiedEntries[entryNumber] = true
|
||||
file, err := os.Create(notifiedFilePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error saving notified entries: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
err = json.NewEncoder(file).Encode(notifiedEntries)
|
||||
if err != nil {
|
||||
log.Fatalf("Error encoding notified entries: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func checkAndSendNotifications() {
|
||||
for _, blog := range blogs {
|
||||
for _, entry := range blog.Entries {
|
||||
if !entry.Notified && !time.Now().Before(entry.Date) {
|
||||
sendNotifications(entry)
|
||||
entry.Notified = true
|
||||
saveNotifiedEntry(entry.Number)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue