summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2023-07-27 19:03:41 +0200
committerPhilipp Tanlak <philipp.tanlak@gmail.com>2023-07-27 19:03:41 +0200
commita9b61f84070cc7ca0d6e26f187c745619a91422a (patch)
treed69b67142b6de860d7da23bd5ff8c62af0aaca1e /cmd
init
Diffstat (limited to 'cmd')
-rw-r--r--cmd/flyscrape/main.go44
1 files changed, 44 insertions, 0 deletions
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))
+}