Skip to content

Commit

Permalink
quote api
Browse files Browse the repository at this point in the history
  • Loading branch information
AwesomeYelim committed Dec 12, 2024
1 parent d367e6f commit e39fc1e
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 15 deletions.
6 changes: 5 additions & 1 deletion executor/bulletin/forPresentation/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func CreatePresentation(figmaInfo *get.Info, execPath string, config extract.Con
objPdf.AddPage()
objPdf.CheckImgPlaced(bulletinSize, imgPath, 0)
if strings.Contains(con.Info, "edit") {
objPdf.WriteText(148.5, 110, 27, con.Content, highestLuminaceColor)
if strings.HasPrefix(con.Title, "2_") {
objPdf.WriteText(148.5, 110, 27, con.Obj, highestLuminaceColor)
} else {
objPdf.WriteText(148.5, 110, 27, con.Content, highestLuminaceColor)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion executor/bulletin/forPrint/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func CreatePrint(figmaInfo *get.Info, execPath string, config extract.Config) {

if i == 0 {
sunDatText := date.SetThisSunDay()
objPdf.WriteText(bulletinSize.Wd-padding, padding, 10, sunDatText, highestLuminaceColor)
objPdf.WriteText(bulletinSize.Wd-(padding*3), padding, 10, sunDatText, highestLuminaceColor)
}

}
Expand Down
1 change: 1 addition & 0 deletions internal/figma/get/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Children struct {
Title string `json:"title"`
Content string `json:"content"`
Info string `json:"info"`
Obj string `json:"obj"`
}

type Info struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/figma/get/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func (i *Info) GetResource(target string) {
log.Print("err : ", err)
}
var newG []Children

_ = os.WriteFile(filepath.Join(i.ExecPath, "config", "test.json"), sample, 0644)

grouped := orgJson(mainContent, i.ExecPath, target)

var keys []string
Expand All @@ -108,6 +111,7 @@ func (i *Info) GetResource(target string) {
Title: key,
Content: temp[0].Content,
Info: temp[0].Info,
Obj: temp[0].Obj,
})
}

Expand Down
123 changes: 110 additions & 13 deletions internal/figma/get/util.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package get

import (
"encoding/json"
"fmt"
"github.com/torie/figma"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"unicode"
)

Expand All @@ -27,7 +33,7 @@ func orgJson(argResult []map[string]interface{}, execPath string, target string)
grouped = orgJson(convertToMapSlice(children), execPath, target)
}
case isValidPattern(name):
grouped[name] = extractChildren(contentResult)
grouped[name] = extractChildren(contentResult, name)
}
}
}
Expand All @@ -49,7 +55,7 @@ func isValidPattern(name string) bool {
}

// 하위 항목에서 자식 요소 추출
func extractChildren(contentResult map[string]interface{}) []Children {
func extractChildren(contentResult map[string]interface{}, name string) []Children {
var children []Children

if childItems, ok := contentResult["children"].([]interface{}); ok {
Expand All @@ -59,26 +65,117 @@ func extractChildren(contentResult map[string]interface{}) []Children {
characters, cOk := childMap["characters"].(string)

if nOk && cOk {
children = append(children, Children{
Content: characters,
Info: cName,
})
if strings.HasSuffix(name, "부름") || strings.HasSuffix(name, "봉독") {
children = append(children, Children{
Content: characters,
Info: cName,
Obj: displayQuote(characters),
})

} else {
children = append(children, Children{
Content: characters,
Info: cName,
})
}

}

// children 존재할 경우 재귀
//if nestedChildren, ok := childMap["children"].([]interface{}); ok {
// nestedResult := extractChildren(map[string]interface{}{
// "children": nestedChildren,
// })
// children = append(children, nestedResult...)
//}
}
}
}

return children
}

func StripTags(html string) string {
html = strings.ReplaceAll(html, "\u003c", "<")
html = strings.ReplaceAll(html, "\u003e", ">")
html = strings.ReplaceAll(html, "&nbsp;", " ")
html = strings.ReplaceAll(html, "\r\n", "\n")

lines := strings.Split(html, "\n")
var result []string

for _, line := range lines {
line = removeTags(line)

if strings.TrimSpace(line) != "" {
result = append(result, strings.TrimSpace(line))
}
}

return strings.Join(result, "\n")
}

func removeTags(input string) string {
var output strings.Builder
inTag := false
for _, char := range input {
if char == '<' {
inTag = true
} else if char == '>' {
inTag = false
} else if !inTag {
output.WriteRune(char)
}
}
return output.String()
}

func displayQuote(characters string) string {

var dictB map[string]struct {
Eng string `json:"eng"`
Kor string `json:"kor"`
}

dict, err := os.ReadFile(filepath.Join("./config", "bible_dict.json"))
err = json.Unmarshal(dict, &dictB)
char := strings.Split(characters, " ")
cover := ExpandRange(char[1])

url := fmt.Sprintf("http://ibibles.net/quote.php?kor-%s/%s", dictB[char[0]].Eng, cover)

// HTTP GET 요청 생성
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error:", err)
return ""
}
defer resp.Body.Close() // 응답이 끝난 후 자원 해제

if resp.StatusCode != http.StatusOK {
fmt.Println("Failed to fetch data. Status code:", resp.StatusCode)
return ""
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return ""
}

return StripTags(string(body))
}

func ExpandRange(input string) string {
parts := strings.Split(input, ":")
if len(parts) != 2 {
return input
}

prefix := parts[0]
rangePart := parts[1]

rangeNumbers := strings.Split(rangePart, "-")
if len(rangeNumbers) != 2 {
return input
}

return fmt.Sprintf("%s:%s-%s:%s", prefix, rangeNumbers[0], prefix, rangeNumbers[1])
}

// []interface{} => []map[string]interface{}
func convertToMapSlice(data []interface{}) []map[string]interface{} {
var result []map[string]interface{}
Expand Down

0 comments on commit e39fc1e

Please sign in to comment.