adding fetching and saving an entire book
This commit is contained in:
@@ -7,6 +7,7 @@ import(
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"strconv"
|
||||
"strings"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func FetchChapter(cfg *config.Cfg , searchedChapter string) ( error){
|
||||
@@ -33,12 +34,13 @@ func FetchChapter(cfg *config.Cfg , searchedChapter string) ( error){
|
||||
|
||||
chapterNum, err := strconv.Atoi(searchedChapter)
|
||||
if err != nil{
|
||||
log.Printf("searched chapter %v is not a valid number%v", searchedChapter, err)
|
||||
log.Printf("searched chapter %v is not a valid number - %v", searchedChapter, err)
|
||||
}
|
||||
|
||||
chapterText := config.Chapter{
|
||||
Number: chapterNum,
|
||||
}
|
||||
|
||||
replacer := strings.NewReplacer(
|
||||
"L'Éternel", "YAHWEH",
|
||||
"l'Éternel", "YAHWEH",
|
||||
@@ -65,22 +67,35 @@ func FetchChapter(cfg *config.Cfg , searchedChapter string) ( error){
|
||||
|
||||
chapterText = StripAlternativeVersification(chapterText)
|
||||
cfg.Book.Chapters = append(cfg.Book.Chapters, chapterText)
|
||||
|
||||
err= SaveChapter(*cfg, &chapterText)
|
||||
if err != nil{
|
||||
log.Printf("Error saving chapter %v in yaml format.", chapterNum)
|
||||
return fmt.Errorf("Error saving chapter %v in yaml format.", chapterNum)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
func fecthBook (book, version string, chapterNumbers int) book, error{
|
||||
failedChapter := 0
|
||||
bookChapters := book{}
|
||||
|
||||
for i:= 1 ; i > chapterNumbers ; i++{
|
||||
verses, err := fetchChapter(book, strconv.Itoa(i), version)
|
||||
func FetchBook (cfg *config.Cfg) error{
|
||||
|
||||
chapterNum, exist := cfg.BookList[cfg.Book.Name]
|
||||
|
||||
if !exist {
|
||||
log.Printf("%v is not a Bible book or has not been inserted yet.", cfg.Book.Name)
|
||||
return fmt.Errorf("%v is not a Bible book or has not been inserted yet.", cfg.Book.Name)
|
||||
}
|
||||
|
||||
for i:= 1 ; i <= chapterNum ; i++{
|
||||
err := FetchChapter(cfg, strconv.Itoa(i))
|
||||
if err != nil {
|
||||
failedChapter++
|
||||
log.Printf("%s", err)
|
||||
log.Printf("Warning : chapter %v has not been fetched: %v", i, err)
|
||||
continue
|
||||
}
|
||||
book.chapters = append(book,
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user