summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-11-28 21:55:26 -0500
committersiddharth <s@ricketyspace.net>2021-11-28 21:55:26 -0500
commit7d65a623291221f097af12bfd3c2994550d776f6 (patch)
treebe8fe1dc6c3ea68687f71053dd9709aa486732ab
parente23508b1df1b362093fb9e5d5a203ddbb95fbd96 (diff)
fern: flush out main
-rw-r--r--fern.go56
1 files changed, 55 insertions, 1 deletions
diff --git a/fern.go b/fern.go
index 25fa8c9..4908483 100644
--- a/fern.go
+++ b/fern.go
@@ -3,4 +3,58 @@
package main
-func main() {}
+import (
+ "fmt"
+ "os"
+
+ "ricketyspace.net/fern/config"
+ "ricketyspace.net/fern/db"
+ "ricketyspace.net/fern/state"
+)
+
+var fConf *config.FernConfig
+var pState *state.ProcessState
+
+func init() {
+ var err error
+
+ fConf, err = config.Read()
+ if err != nil {
+ fmt.Printf("Error: %v\n", err.Error())
+ os.Exit(1)
+ }
+
+ pState = state.NewProcessState()
+ pState.YDLPath = fConf.YDLPath
+ pState.DumpDir = fConf.DumpDir
+
+ // Open database.
+ pState.DB, err = db.Open()
+ if err != nil {
+ fmt.Printf("Error: %v\n", err.Error())
+ os.Exit(1)
+ }
+}
+
+func main() {
+ defer pState.DB.Write() // Write database to disk before returning.
+
+ // Process all feeds.
+ for _, feed := range fConf.Feeds {
+ f := feed
+ go f.Process(pState)
+ pState.FeedsProcessing += 1
+ }
+ // Wait for all feeds finish processing.
+ for pState.FeedsProcessing > 0 {
+ fr := <-pState.FeedResultChan
+ if fr.Err == nil {
+ fmt.Printf("[%s]: %s\n",
+ fr.FeedId, fr.FeedResult)
+ } else {
+ fmt.Printf("[%s]: %s: %v\n",
+ fr.FeedId, fr.FeedResult, fr.Err.Error())
+ }
+ pState.FeedsProcessing -= 1
+ }
+}