Skip to content

Commit

Permalink
Merge pull request #15 from piqoni/prefix_suffix_for_md_files
Browse files Browse the repository at this point in the history
Add prefix/suffix configuration for Markdown files
  • Loading branch information
piqoni authored Jan 7, 2023
2 parents 09ee1ac + 3415dc0 commit fd97389
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ weather_latitude: 37.77
weather_longitude: 122.41
terminal_mode: false
opml_file_path:
markdown_file_prefix:
markdown_file_suffix:
```
### Command line Options
Run matcha with --help option to see current cli options:
Expand Down
13 changes: 11 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ instapaper: true
weather_latitude: 37.77
weather_longitude: 122.41
terminal_mode: false
opml_file_path: `
opml_file_path:
markdown_file_prefix:
markdown_file_suffix: `

func parseOPML(xmlContent []byte) []RSS {
o := Opml{}
Expand Down Expand Up @@ -97,6 +99,12 @@ func bootstrapConfig() {
if viper.IsSet("weather_longitude") {
lon = viper.Get("weather_longitude").(float64)
}
if viper.IsSet("markdown_file_prefix") {
mdPrefix = viper.Get("markdown_file_prefix").(string)
}
if viper.IsSet("markdown_file_suffix") {
mdSuffix = viper.Get("markdown_file_suffix").(string)
}

var limit int
for _, feed := range feeds.([]any) {
Expand Down Expand Up @@ -163,7 +171,8 @@ func bootstrapConfig() {
check(err)

if !terminal_mode {
err := os.Remove(filepath.Join(markdown_dir_path, currentDate+".md"))
markdown_file_name := mdPrefix + currentDate + mdSuffix + ".md"
err := os.Remove(filepath.Join(markdown_dir_path, markdown_file_name))
if err != nil {
// fmt.Println("INFO: Coudn't remove old file: ", err)
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

var markdown_dir_path string
var mdPrefix, mdSuffix string
var terminal_mode bool = false
var currentDate = time.Now().Format("2006-01-02")
var lat, lon float64
Expand Down Expand Up @@ -81,7 +82,8 @@ func writeToMarkdown(body string) {
if terminal_mode {
fmt.Println(body)
} else {
f, err := os.OpenFile(filepath.Join(markdown_dir_path, currentDate+".md"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
markdown_file_name := mdPrefix + currentDate + mdSuffix + ".md"
f, err := os.OpenFile(filepath.Join(markdown_dir_path, 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 fd97389

Please sign in to comment.