Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
pejman-hkh committed Oct 10, 2024
1 parent 1fff022 commit 43f112d
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 889 deletions.
File renamed without changes.
File renamed without changes.
8 changes: 0 additions & 8 deletions examples/go.mod

This file was deleted.

17 changes: 0 additions & 17 deletions examples/gox/main.go

This file was deleted.

87 changes: 0 additions & 87 deletions examples/gox/test.go

This file was deleted.

93 changes: 0 additions & 93 deletions examples/gox/test.gox

This file was deleted.

10 changes: 0 additions & 10 deletions examples/imdbapi/Dockerfile

This file was deleted.

4 changes: 0 additions & 4 deletions examples/imdbapi/Makefile

This file was deleted.

5 changes: 0 additions & 5 deletions examples/imdbapi/go.mod

This file was deleted.

Empty file removed examples/imdbapi/go.sum
Empty file.
37 changes: 18 additions & 19 deletions examples/imdbapi/imdbApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"strings"

"github.com/pejman-hkh/gdp/gdp"
"gdp/gdp"
)

type Casts map[int]map[string]string
Expand All @@ -22,13 +22,6 @@ func inArray(key string, array []string) bool {
}

func imdbApi(content string) map[string]interface{} {
defer func() {
r := recover()

if r != nil {
fmt.Println("RECOVER", r)
}
}()

document := gdp.Default(content)
epic := document.Find(".ipc-image").Eq(0)
Expand All @@ -54,17 +47,21 @@ func imdbApi(content string) map[string]interface{} {
casts := make(map[string]Casts)
document.Find(".ipc-inline-list").Each(func(ii int, t *gdp.Tag) {

title := t.Parent().Prev().Html()
if inArray(title, arr) {
casts[title] = Casts{}
castArray := make(Casts)
i := 0
t.Find("a").Each(func(iii int, a *gdp.Tag) {
cast := map[string]string{"name": a.Html(), "link": a.Attr("href")}
castArray[i] = cast
i++
})
casts[title] = castArray
title := t.Prev().Html()

if title != "" {

if inArray(title, arr) {
casts[title] = Casts{}
castArray := make(Casts)
i := 0
t.Find("a").Each(func(iii int, a *gdp.Tag) {
cast := map[string]string{"name": a.Html(), "link": a.Attr("href")}
castArray[i] = cast
i++
})
casts[title] = castArray
}
}
})

Expand Down Expand Up @@ -139,6 +136,8 @@ func routes(w http.ResponseWriter, req *http.Request) {
if res != nil {
defer res.Body.Close()
b, _ := io.ReadAll(res.Body)
// fmt.Print(string(b))
// os.Exit(0)

api := imdbApi(string(b))
marshal, _ := json.Marshal(api)
Expand Down
4 changes: 2 additions & 2 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"fmt"
"os"

"github.com/pejman-hkh/gdp/gdp"
"gdp/gdp"
)

func main() {

fileContent, _ := os.ReadFile("fightclub.html")
fileContent, _ := os.ReadFile("./data/fightclub.html")
document := gdp.Default(string(fileContent))
found := document.Find(".ipc-image")
fmt.Printf("%+v\n", found.Eq(0).Attr("src"))
Expand Down
13 changes: 0 additions & 13 deletions examples/react/README.md

This file was deleted.

68 changes: 0 additions & 68 deletions examples/react/main.go

This file was deleted.

Loading

0 comments on commit 43f112d

Please sign in to comment.