Skip to content

Commit

Permalink
show pronounce for query result
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyYe committed Sep 11, 2017
1 parent e93c6a2 commit 27244ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[1]: https://travis-ci.org/TimothyYe/ydict.svg?branch=master
[2]: https://travis-ci.org/TimothyYe/ydict
[3]: https://img.shields.io/badge/release-v0.6-brightgreen.svg
[3]: https://img.shields.io/badge/release-v0.7-brightgreen.svg
[4]: https://github.com/TimothyYe/ydict/releases
[5]: https://img.shields.io/dub/l/vibe-d.svg
[6]: LICENSE
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ func main() {
}

words := strings.Join(os.Args[1:], " ")
query(words)
query(words, len(os.Args[1:]) > 1)
}
25 changes: 24 additions & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
proxier "golang.org/x/net/proxy"
)

func query(word string) {
func query(word string, isMulti bool) {
var url string
var doc *goquery.Document
isChinese := isChinese(word)
Expand Down Expand Up @@ -62,6 +62,11 @@ func query(word string) {
color.Green(" %s", s.Find(".search-js").Text())
})
} else {
// Find the pronounce
if !isMulti {
color.Green("\r\n %s", getPronounce(doc))
}

// Find the result
result := doc.Find("div#phrsListTab > div.trans-container > ul").Text()
color.Green(result)
Expand All @@ -79,6 +84,24 @@ func query(word string) {
}
}

func getPronounce(doc *goquery.Document) string {
var pronounce string
doc.Find("div.baav > span.pronounce").Each(func(i int, s *goquery.Selection) {

if i == 0 {
p := fmt.Sprintf("英: %s ", s.Find("span.phonetic").Text())
pronounce += p
}

if i == 1 {
p := fmt.Sprintf("美: %s", s.Find("span.phonetic").Text())
pronounce += p
}
})

return pronounce
}

func getSentences(doc *goquery.Document, isChinese bool) [][]string {
result := [][]string{}
doc.Find("#bilingual ul li").Each(func(_ int, s *goquery.Selection) {
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
██║ ██████╔╝██║╚██████╗ ██║
╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝
YDict V0.6
YDict V0.7
https://github.com/TimothyYe/ydict
`
Expand Down

0 comments on commit 27244ca

Please sign in to comment.