Skip to content

Commit 73c5cea

Browse files
Make output dir configurable
1 parent ac2cab0 commit 73c5cea

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

internal/config/config.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import (
44
"errors"
55
"os"
66
"strconv"
7+
"strings"
78
"sync"
89
)
910

1011
// Config is a struct that holds the configuration for the application
1112
type Config struct {
1213
// DatabasePath is the path to the sqlite database
1314
DatabasePath string
15+
// OutputDirectory is the directory where the output files are stored
16+
OutputDirectory string
1417
// DiscordToken is the token for the discord bot
1518
DiscordToken string
1619
// MailServer is the address of the mail server
@@ -34,12 +37,16 @@ func GetConfig() (*Config, error) {
3437
if instance == nil {
3538
once.Do(func() {
3639
instance = &Config{
37-
DatabasePath: "./kindExport.sqlite",
38-
DiscordToken: "",
39-
MailServer: "",
40-
MailPort: 587,
41-
MailUser: "",
42-
MailPassword: "",
40+
DatabasePath: "./kindExport.sqlite",
41+
OutputDirectory: "./output",
42+
DiscordToken: "",
43+
MailServer: "",
44+
MailPort: 587,
45+
MailUser: "",
46+
MailPassword: "",
47+
}
48+
if os.Getenv("OUTPUT_DIRECTORY") != "" {
49+
instance.OutputDirectory = strings.TrimRight(os.Getenv("OUTPUT_DIRECTORY"), "/")
4350
}
4451
if os.Getenv("DATABASE_PATH") != "" {
4552
instance.DatabasePath = os.Getenv("DATABASE_PATH")

internal/scrape/substack_scraper.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"golang.org/x/text/transform"
1212
"golang.org/x/text/unicode/norm"
1313
"google.golang.org/appengine/log"
14+
"kindExport/internal/config"
1415
"net/http"
1516
"net/url"
1617
"os"
@@ -244,15 +245,15 @@ func (s SubstackScraper) Scrape(url *string) (*Book, error) {
244245
}
245246

246247
// Create output dir if not already existing
247-
248-
err = os.MkdirAll("output", os.ModePerm)
248+
conf, _ := config.GetConfig()
249+
err = os.MkdirAll(fmt.Sprintf("%s/%s", conf.OutputDirectory, book.Title()), os.ModePerm)
249250
if err != nil {
250251
log.Errorf(nil, "Failed to create output directory: %s", err.Error())
251252
return nil, err
252253
}
253254

254255
// We can now create an EPUB from the parsed HTML content
255-
epubPath := fmt.Sprintf("output/%s.epub", book.Title())
256+
epubPath := fmt.Sprintf("%s/%s.epub", conf.OutputDirectory, book.Title())
256257
err = book.Write(epubPath)
257258

258259
if err != nil {

0 commit comments

Comments
 (0)