Skip to content

Commit

Permalink
more refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
piqoni committed Sep 9, 2023
1 parent d291d7a commit 30d27de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
21 changes: 10 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/xml"
"flag"
"fmt"
"io/ioutil"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -78,7 +77,7 @@ func bootstrapConfig() {
log.Println(direrr)
}
// if -t parameter is passed overwrite terminal_mode setting in config.yml
flag.BoolVar(&terminal_mode, "t", terminal_mode, "Run Matcha in Terminal Mode, no markdown files will be created")
flag.BoolVar(&terminalMode, "t", terminalMode, "Run Matcha in Terminal Mode, no markdown files will be created")
configFile := flag.String("c", "", "Config file path (if you want to override the current directory config.yaml)")
opmlFile := flag.String("o", "", "OPML file path to append feeds from opml files")
build := flag.Bool("build", false, "Dev: Build matcha binaries in the bin directory")
Expand All @@ -105,9 +104,9 @@ func bootstrapConfig() {
}

if viper.IsSet("markdown_dir_path") {
mdDirPath = viper.Get("markdown_dir_path").(string)
markdownDirPath = viper.Get("markdown_dir_path").(string)
} else {
mdDirPath = currentDir
markdownDirPath = currentDir
}
myFeeds = []RSS{}
feeds := viper.Get("feeds")
Expand Down Expand Up @@ -158,18 +157,18 @@ func bootstrapConfig() {
// Import any config.opml file on current direcotory
configPath := currentDir + "/" + "config.opml"
if _, err := os.Stat(configPath); err == nil {
xmlContent, _ := ioutil.ReadFile(currentDir + "/" + "config.opml")
xmlContent, _ := os.ReadFile(currentDir + "/" + "config.opml")
myFeeds = append(myFeeds, parseOPML(xmlContent)...)
}
// Append any opml file added by -o parameter
if len(*opmlFile) > 0 {
xmlContent, _ := ioutil.ReadFile(*opmlFile)
xmlContent, _ := os.ReadFile(*opmlFile)
myFeeds = append(myFeeds, parseOPML(xmlContent)...)
}

// Append opml file from config.yml
if viper.IsSet("opml_file_path") {
xmlContent, _ := ioutil.ReadFile(viper.Get("opml_file_path").(string))
xmlContent, _ := os.ReadFile(viper.Get("opml_file_path").(string))
myFeeds = append(myFeeds, parseOPML(xmlContent)...)
}

Expand All @@ -178,8 +177,8 @@ func bootstrapConfig() {
show_images = viper.GetBool("show_images")

// Overwrite terminal_mode from config file only if its not set through -t flag
if !terminal_mode {
terminal_mode = viper.GetBool("terminal_mode")
if !terminalMode {
terminalMode = viper.GetBool("terminal_mode")
}

databaseFilePath := viper.GetString("database_file_path")
Expand All @@ -197,9 +196,9 @@ func bootstrapConfig() {
log.Println("Coudn't apply migrations:", err)
}

if !terminal_mode {
if !terminalMode {
markdown_file_name := mdPrefix + currentDate + mdSuffix + ".md"
os.Remove(filepath.Join(mdDirPath, markdown_file_name))
os.Remove(filepath.Join(markdownDirPath, markdown_file_name))
}
}

Expand Down
10 changes: 5 additions & 5 deletions feeds_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/mmcdole/gofeed"
)

var mdDirPath string
var markdownDirPath string
var mdPrefix, mdSuffix string
var terminal_mode bool = false
var terminalMode bool = false
var currentDate = time.Now().Format("2006-01-02")
var lat, lon float64
var instapaper bool
Expand All @@ -42,7 +42,7 @@ type Writer interface {
}

func getWriter() Writer {
if terminal_mode {
if terminalMode {
return TerminalWriter{}
}
return MarkdownWriter{}
Expand Down Expand Up @@ -180,7 +180,7 @@ func generateFeedItems(w Writer, feed *gofeed.Feed, rss RSS) string {
}

// Add the Instapaper link if enabled
if instapaper && !terminal_mode {
if instapaper && !terminalMode {
items += getInstapaperLink(item.Link)
}

Expand All @@ -199,7 +199,7 @@ func generateFeedItems(w Writer, feed *gofeed.Feed, rss RSS) string {
items += w.writeSummary(summary, true)
}

if show_images && !terminal_mode {
if show_images && !terminalMode {
img := ExtractImageTagFromHTML(item.Content)
if img != "" {
items += img + "\n"
Expand Down
2 changes: 1 addition & 1 deletion markdown_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type MarkdownWriter struct{}

func (w MarkdownWriter) write(body string) {
markdown_file_name := mdPrefix + currentDate + mdSuffix + ".md"
f, err := os.OpenFile(filepath.Join(mdDirPath, markdown_file_name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(filepath.Join(markdownDirPath, markdown_file_name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 30d27de

Please sign in to comment.