Skip to content

Commit

Permalink
use HTTPS, update deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyYe committed Aug 16, 2019
1 parent f3dcbf7 commit e745993
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func query(words []string, withVoice, withMore, isQuiet, isMulti bool) {
isChinese := isChinese(queryString)

if isChinese {
url = "http://dict.youdao.com/w/eng/%s"
url = "https://dict.youdao.com/w/eng/%s"
} else {
url = "http://dict.youdao.com/w/%s"
url = "https://dict.youdao.com/w/%s"
}

//Init spinner
Expand Down Expand Up @@ -70,20 +70,19 @@ func query(words []string, withVoice, withMore, isQuiet, isMulti bool) {
os.Exit(1)
}

doc, _ = goquery.NewDocumentFromResponse(resp)
doc, _ = goquery.NewDocumentFromReader(resp.Body)

if withVoice && isAvailableOS() {
if resp, err := client.Get(fmt.Sprintf(voiceURL, voiceString)); err == nil {
voiceBody = resp.Body
}
}
} else {
var err error
doc, err = goquery.NewDocument(fmt.Sprintf(url, queryString))

if err != nil {
log.Fatal(err)
if resp, err := http.Get(fmt.Sprintf(url, queryString)); err != nil {
color.Red("Query failed with err: %s", err.Error())
os.Exit(1)
} else {
doc, _ = goquery.NewDocumentFromReader(resp.Body)
}

if withVoice && isAvailableOS() {
Expand Down Expand Up @@ -113,7 +112,6 @@ func query(words []string, withVoice, withMore, isQuiet, isMulti bool) {
fmt.Printf("%s\n", color.GreenString(strings.Join(meanings, "; ")))
})
} else {

// Check for typos
if hint := getHint(doc); hint != nil {
color.Blue("\r\n word '%s' not found, do you mean?", queryString)
Expand Down Expand Up @@ -221,12 +219,15 @@ func getSentences(words []string, doc *goquery.Document, isChinese, withMore boo
result := [][]string{}
if withMore {
url := fmt.Sprintf("http://dict.youdao.com/example/blng/eng/%s", strings.Join(words, "_"))
var err error
doc, err = goquery.NewDocument(url)
if err != nil {
return result

if resp, err := http.Get(url); err != nil {
color.Red("Query failed with err: %s", err.Error())
os.Exit(1)
} else {
doc, _ = goquery.NewDocumentFromReader(resp.Body)
}
}

doc.Find("#bilingual ul li").Each(func(_ int, s *goquery.Selection) {
r := []string{}
s.Children().Each(func(ii int, ss *goquery.Selection) {
Expand Down

0 comments on commit e745993

Please sign in to comment.