From a9b61f84070cc7ca0d6e26f187c745619a91422a Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Thu, 27 Jul 2023 19:03:41 +0200 Subject: init --- cmd/flyscrape/main.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 cmd/flyscrape/main.go (limited to 'cmd') diff --git a/cmd/flyscrape/main.go b/cmd/flyscrape/main.go new file mode 100644 index 0000000..1b94d71 --- /dev/null +++ b/cmd/flyscrape/main.go @@ -0,0 +1,44 @@ +package main + +import ( + _ "embed" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + + "flyscrape/js" +) + +func main() { + if len(os.Args) != 2 { + fmt.Fprintln(os.Stderr, "Please provide a file to run.") + os.Exit(1) + } + + opts, run, err := js.Compile(os.Args[1]) + if err != nil { + panic(err) + } + + resp, err := http.Get(opts.URL) + if err != nil { + panic(err) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + panic(err) + } + + out := run(js.RunOptions{HTML: string(body)}) + + j, err := json.MarshalIndent(out, "", " ") + if err != nil { + panic(err) + } + + fmt.Println(string(j)) +} -- cgit v1.2.3