Skip to content

Commit

Permalink
updated err
Browse files Browse the repository at this point in the history
  • Loading branch information
Xatta-Trone committed Jun 28, 2023
1 parent 77f2da7 commit 6d5e324
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type Synonym struct {
func GetResult(word string) (WordResponse, error) {

var finalResult WordResponse
var err error

// temp PoS and Def
tempPoS := []string{}
Expand All @@ -115,8 +116,14 @@ func GetResult(word string) (WordResponse, error) {
// StartRequestsFunc: func(g *geziyor.Geziyor) {
// g.GetRendered("https://www.thesaurus.com/browse/"+word, g.Opt.ParseFunc)
// },
StartURLs: []string{"https://www.thesaurus.com/browse/"+word},
StartURLs: []string{"https://www.thesaurus.com/browse/" + word},
ParseFunc: func(g *geziyor.Geziyor, r *client.Response) {

if r.StatusCode != http.StatusOK {
fmt.Println("There was an error, ", r.Status)
err = fmt.Errorf("%s", r.Status)
}

// fmt.Println(string(r.Body))

root := r.HTMLDoc.Find("[data-type='thesaurus-entry-module']")
Expand Down Expand Up @@ -157,10 +164,13 @@ func GetResult(word string) (WordResponse, error) {

singleSynonymObj := Synonym{}

singleSynonymObj.Definition = tempDef[0]
singleSynonymObj.PartsOfSpeech = tempPoS[0]
singleSynonymObj.Syns = singleGroup
finalResult.Synonyms = append(finalResult.Synonyms, singleSynonymObj)
if len(tempDef) > 0 {
singleSynonymObj.Definition = tempDef[0]
singleSynonymObj.PartsOfSpeech = tempPoS[0]
singleSynonymObj.Syns = singleGroup
finalResult.Synonyms = append(finalResult.Synonyms, singleSynonymObj)

}

// now find the antonyms
antonyms := []string{}
Expand All @@ -178,7 +188,7 @@ func GetResult(word string) (WordResponse, error) {
//BrowserEndpoint: "ws://localhost:3000",
}).Start()

return finalResult, nil
return finalResult, err

// Request the HTML page.
res, err := http.Get("https://www.thesaurus.com/browse/" + word)
Expand Down

0 comments on commit 6d5e324

Please sign in to comment.