refactoring with internal
This commit is contained in:
39
cmd/main.go
39
cmd/main.go
@@ -1,9 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import(
|
import(
|
||||||
|
"project.hechon.fr/internal/fetcher"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"project.hechon.fr/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadExclude(path string) (map[string]struct{}, error) {
|
func loadExclude(path string) (map[string]struct{}, error) {
|
||||||
@@ -20,28 +22,47 @@ func loadExclude(path string) (map[string]struct{}, error) {
|
|||||||
|
|
||||||
func main (){
|
func main (){
|
||||||
|
|
||||||
properName, err:= loadExclude("properName.txt")
|
book := config.Book{
|
||||||
|
Name: "Psaumes",
|
||||||
|
Version: "LSG",
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := config.Cfg{
|
||||||
|
ConfigPath: "internal/config/",
|
||||||
|
YamlPath: "data",
|
||||||
|
HtmlPath: "Public",
|
||||||
|
BookList: map[string]int{
|
||||||
|
"ps": 150,
|
||||||
|
"pr": 31,
|
||||||
|
},
|
||||||
|
|
||||||
|
Book: book,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
properName, err:= loadExclude(cfg.ConfigPath + "properName.txt")
|
||||||
if err != nil{
|
if err != nil{
|
||||||
log.Printf("can’t open the proper names file")
|
log.Printf("can’t open the proper names file")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
book := "Psaumes"
|
cfg.ProperName = properName
|
||||||
searchedChapter := "2"
|
|
||||||
version := "LSG"
|
|
||||||
|
|
||||||
Chapter, err := fetchChapter(book, searchedChapter, version)
|
searchedChapter := "2"
|
||||||
|
|
||||||
|
err = fetcher.FetchChapter(&cfg, searchedChapter)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("GET %s %s %s failed\n", book, searchedChapter, version)
|
log.Printf("GET %s %s %s failed\n", book, searchedChapter, cfg.Book.Version)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Chapter = stripAlternativeVersification(Chapter)
|
|
||||||
|
|
||||||
for i, verse := range Chapter.verses{
|
/*
|
||||||
|
for i, verse := range cfg.Book.Chapters[0].Verses{
|
||||||
log.Printf("==== Verse: %v ====", i+1)
|
log.Printf("==== Verse: %v ====", i+1)
|
||||||
splitInPart(verse, properName)
|
fetcher.SplitInPart(verse, properName)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|||||||
21
internal/config/config.go
Normal file
21
internal/config/config.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type Chapter struct{
|
||||||
|
Verses []string
|
||||||
|
Number int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Book struct{
|
||||||
|
Chapters []Chapter
|
||||||
|
Version string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Cfg struct{
|
||||||
|
Book Book
|
||||||
|
ConfigPath string
|
||||||
|
YamlPath string
|
||||||
|
HtmlPath string
|
||||||
|
BookList map[string]int
|
||||||
|
ProperName map[string]struct{}
|
||||||
|
}
|
||||||
@@ -1,43 +1,44 @@
|
|||||||
package main
|
package fetcher
|
||||||
|
|
||||||
import(
|
import(
|
||||||
|
"project.hechon.fr/internal/config"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
type chapter struct{
|
|
||||||
verses []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type book struct{
|
func FetchChapter(cfg *config.Cfg , searchedChapter string) ( error){
|
||||||
chapters []chapter
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchChapter(book, searchedChapter, version string) (chapter, error){
|
url := "https://www.biblegateway.com/passage/?search=" + cfg.Book.Name + "%20" + searchedChapter +"&version=" + cfg.Book.Version
|
||||||
|
|
||||||
url := "https://www.biblegateway.com/passage/?search=" + book + "%20" + searchedChapter +"&version=" + version
|
|
||||||
|
|
||||||
res, err := http.Get(url)
|
res, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can’t get %s : %v\n", url, err)
|
log.Printf("can’t get %s : %v\n", url, err)
|
||||||
return chapter{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
log.Printf("error code %v: %v\n", res.StatusCode, res.Status)
|
log.Printf("error %v\n", res.Status)
|
||||||
return chapter{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error reading the http response: %v\n", err)
|
log.Printf("error reading the http response: %v\n", err)
|
||||||
return chapter{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
chapterText := chapter{}
|
chapterNum, err := strconv.Atoi(searchedChapter)
|
||||||
|
if err != nil{
|
||||||
|
log.Printf("searched chapter %v is not a valid number%v", searchedChapter, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
chapterText := config.Chapter{
|
||||||
|
Number: chapterNum,
|
||||||
|
}
|
||||||
replacer := strings.NewReplacer(
|
replacer := strings.NewReplacer(
|
||||||
"L'Éternel", "YAHWEH",
|
"L'Éternel", "YAHWEH",
|
||||||
"l'Éternel", "YAHWEH",
|
"l'Éternel", "YAHWEH",
|
||||||
@@ -59,10 +60,12 @@ func fetchChapter(book, searchedChapter, version string) (chapter, error){
|
|||||||
verse, _ = strings.CutPrefix(rawText, strconv.Itoa(i+1))
|
verse, _ = strings.CutPrefix(rawText, strconv.Itoa(i+1))
|
||||||
}
|
}
|
||||||
verse = replacer.Replace(verse)
|
verse = replacer.Replace(verse)
|
||||||
chapterText.verses = append(chapterText.verses, strings.TrimSpace(verse))
|
chapterText.Verses = append(chapterText.Verses, strings.TrimSpace(verse))
|
||||||
})
|
})
|
||||||
|
|
||||||
return chapterText, nil
|
chapterText = StripAlternativeVersification(chapterText)
|
||||||
|
cfg.Book.Chapters = append(cfg.Book.Chapters, chapterText)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package fetcher
|
||||||
|
|
||||||
import(
|
import(
|
||||||
|
"project.hechon.fr/internal/config"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -8,21 +9,28 @@ import(
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stripAlternativeVersification(rawChapter chapter) chapter{
|
func StripAlternativeVersification(rawChapter config.Chapter) config.Chapter{
|
||||||
|
/* a handful of verses have 2 traditions of numbering, the alternative
|
||||||
|
* rendering appears then between brackets. This is a simple use of
|
||||||
|
* regexp to get rid of it
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
regExp:=regexp.MustCompile(`\(\d+:\d+\)`)
|
regExp:=regexp.MustCompile(`\(\d+:\d+\)`)
|
||||||
|
|
||||||
var treatedChapter chapter
|
var treatedChapter config.Chapter
|
||||||
for _, verse := range rawChapter.verses{
|
for _, verse := range rawChapter.Verses{
|
||||||
modifiedVerse := string(regExp.ReplaceAll([]byte(verse), []byte("")))
|
modifiedVerse := string(regExp.ReplaceAll([]byte(verse), []byte("")))
|
||||||
log.Printf("%v\n", modifiedVerse)
|
log.Printf("%v\n", modifiedVerse)
|
||||||
treatedChapter.verses = append(treatedChapter.verses, modifiedVerse)
|
treatedChapter.Verses = append(treatedChapter.Verses, modifiedVerse)
|
||||||
}
|
}
|
||||||
|
|
||||||
return treatedChapter
|
return treatedChapter
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitInPart(verse string, properName map[string]struct{})(){
|
func SplitInPart(verse string, properName map[string]struct{})([]string){
|
||||||
|
|
||||||
|
var parts []string
|
||||||
currentPart := ""
|
currentPart := ""
|
||||||
words := strings.Split(strings.TrimSpace(verse), " ")
|
words := strings.Split(strings.TrimSpace(verse), " ")
|
||||||
wordsCount := len(words)
|
wordsCount := len(words)
|
||||||
@@ -34,7 +42,7 @@ func splitInPart(verse string, properName map[string]struct{})(){
|
|||||||
trimedWord := strings.TrimRight(word, ".,")
|
trimedWord := strings.TrimRight(word, ".,")
|
||||||
_, isProperName := properName[trimedWord]
|
_, isProperName := properName[trimedWord]
|
||||||
if i != 0 && unicode.IsUpper(r) && !isProperName{
|
if i != 0 && unicode.IsUpper(r) && !isProperName{
|
||||||
log.Printf("%s", currentPart)
|
parts = append(parts, currentPart)
|
||||||
currentPart = word
|
currentPart = word
|
||||||
isTreated = true
|
isTreated = true
|
||||||
}else{
|
}else{
|
||||||
@@ -44,7 +52,8 @@ func splitInPart(verse string, properName map[string]struct{})(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isTreated {
|
if !isTreated {
|
||||||
log.Printf("%s", currentPart)
|
parts = append(parts, currentPart)
|
||||||
}
|
}
|
||||||
|
return parts
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
36
ps69.txt
36
ps69.txt
@@ -1,36 +0,0 @@
|
|||||||
"Au chef des chantres. Sur les lis. De David. Sauve-moi, ô Dieu! Car les eaux menacent ma vie."
|
|
||||||
"J'enfonce dans la boue, sans pouvoir me tenir; Je suis tombé dans un gouffre, et les eaux m'inondent."
|
|
||||||
"Je m'épuise à crier, mon gosier se dessèche, Mes yeux se consument, tandis que je regarde vers mon Dieu."
|
|
||||||
"Ils sont plus nombreux que les cheveux de ma tête, Ceux qui me haïssent sans cause; Ils sont puissants, ceux qui veulent me perdre, Qui sont à tort mes ennemis. Ce que je n'ai pas dérobé, il faut que je le restitue."
|
|
||||||
"O Dieu! tu connais ma folie, Et mes fautes ne te sont point cachées."
|
|
||||||
"Que ceux qui espèrent en toi ne soient pas confus à cause de moi, Seigneur, YAHWEH des armées! Que ceux qui te cherchent ne soient pas dans la honte à cause de moi, Dieu d'Israël!"
|
|
||||||
"Car c'est pour toi que je porte l'opprobre, Que la honte couvre mon visage;"
|
|
||||||
"Je suis devenu un étranger pour mes frères, Un inconnu pour les fils de ma mère."
|
|
||||||
"Car le zèle de ta maison me dévore, Et les outrages de ceux qui t'insultent tombent sur moi."
|
|
||||||
"Je verse des larmes et je jeûne, Et c'est ce qui m'attire l'opprobre;"
|
|
||||||
"Je prends un sac pour vêtement, Et je suis l'objet de leurs sarcasmes."
|
|
||||||
"Ceux qui sont assis à la porte parlent de moi, Et les buveurs de liqueurs fortes me mettent en chansons."
|
|
||||||
"Mais je t'adresse ma prière, ô YAHWEH! Que ce soit le temps favorable, ô Dieu, par ta grande bonté! Réponds-moi, en m'assurant ton secours!"
|
|
||||||
"Retire-moi de la boue, et que je n'enfonce plus! Que je sois délivré de mes ennemis et du gouffre!"
|
|
||||||
"Que les flots ne m'inondent plus, Que l'abîme ne m'engloutisse pas, Et que la fosse ne se ferme pas sur moi!"
|
|
||||||
"Exauce-moi, YAHWEH! car ta bonté est immense. Dans tes grandes compassions, tourne vers moi les regards,"
|
|
||||||
"Et ne cache pas ta face à ton serviteur! Puisque je suis dans la détresse, hâte-toi de m'exaucer!"
|
|
||||||
"Approche-toi de mon âme, délivre-la! Sauve-moi, à cause de mes ennemis!"
|
|
||||||
"Tu connais mon opprobre, ma honte, mon ignominie; Tous mes adversaires sont devant toi."
|
|
||||||
"L'opprobre me brise le coeur, et je suis malade; J'attends de la pitié, mais en vain, Des consolateurs, et je n'en trouve aucun."
|
|
||||||
"Ils mettent du fiel dans ma nourriture, Et, pour apaiser ma soif, ils m'abreuvent de vinaigre."
|
|
||||||
"Que leur table soit pour eux un piège, Et un filet au sein de leur sécurité!"
|
|
||||||
"Que leurs yeux s'obscurcissent et ne voient plus, Et fais continuellement chanceler leurs reins!"
|
|
||||||
"Répands sur eux ta colère, Et que ton ardente fureur les atteigne!"
|
|
||||||
"Que leur demeure soit dévastée, Qu'il n'y ait plus d'habitants dans leurs tentes!"
|
|
||||||
"Car ils persécutent celui que tu frappes, Ils racontent les souffrances de ceux que tu blesses."
|
|
||||||
"Ajoute des iniquités à leurs iniquités, Et qu'ils n'aient point part à ta miséricorde!"
|
|
||||||
"Qu'ils soient effacés du livre de vie, Et qu'ils ne soient point inscrits avec les justes!"
|
|
||||||
"Moi, je suis malheureux et souffrant: O Dieu, que ton secours me relève!"
|
|
||||||
"Je célébrerai le nom de Dieu par des cantiques, Je l'exalterai par des louanges."
|
|
||||||
"Cela est agréable à YAHWEH, plus qu'un taureau Avec des cornes et des sabots."
|
|
||||||
"Les malheureux le voient et se réjouissent; Vous qui cherchez Dieu, que votre coeur vive!"
|
|
||||||
"Car YAHWEH écoute les pauvres, Et il ne méprise point ses captifs."
|
|
||||||
"Que les cieux et la terre le célèbrent, Les mers et tout ce qui s'y meut!"
|
|
||||||
"Car Dieu sauvera Sion, et bâtira les villes de Juda; On s'y établira, et l'on en prendra possession;"
|
|
||||||
"La postérité de ses serviteurs en fera son héritage, Et ceux qui aiment son nom y auront leur demeure."
|
|
||||||
Reference in New Issue
Block a user