Verified Commit 25f9c08f authored by Marcel's avatar Marcel

Versuch das Tool zu fixen

parent 6515b68a
result/
tmp/
result
tmp
luftdaten_screenshot_tool*
.idea
\ No newline at end of file
......@@ -6,6 +6,7 @@ import (
"github.com/chromedp/cdproto/cdp"
cdr "github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
"github.com/pkg/errors"
"io/ioutil"
"os"
"time"
......@@ -40,7 +41,10 @@ func Screenshot(urlstr, folderPath string) chromedp.Tasks {
chromedp.Screenshot(`.map`, &buf, chromedp.ByQuery),
chromedp.ActionFunc(func(context.Context, cdp.Executor) error {
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
os.Mkdir(folderPath, os.ModePerm)
err := os.Mkdir(folderPath, os.ModePerm)
if err != nil {
return errors.WithMessage(err, "Failed to call Shutdown")
}
}
files, _ := ioutil.ReadDir(folderPath)
count := len(files) + 1
......
......@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/chromedp/chromedp"
"github.com/chromedp/chromedp/runner"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"gitlab.com/iotssl/luftdaten_screenshot_tool/actions"
"log"
......@@ -47,7 +48,7 @@ func Run(cmd *cobra.Command, args []string) error {
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.UserDataDir("./tmp"),
runner.Port(9222),
runner.RemoteDebuggingPort(9222),
)
} else {
opts = chromedp.WithRunnerOptions(
......@@ -57,7 +58,7 @@ func Run(cmd *cobra.Command, args []string) error {
runner.Flag("no-first-run", true),
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.Port(9222),
runner.RemoteDebuggingPort(9222),
)
}
} else {
......@@ -67,33 +68,33 @@ func Run(cmd *cobra.Command, args []string) error {
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.UserDataDir("./tmp"),
runner.Port(9222),
runner.RemoteDebuggingPort(9222),
)
} else {
opts = chromedp.WithRunnerOptions(
runner.Flag("no-first-run", true),
runner.Flag("no-default-browser-check", true),
runner.WindowSize(1920, 1080),
runner.Port(9222),
runner.RemoteDebuggingPort(9222),
)
}
}
c, err := chromedp.New(ctxt, opts)
if err != nil {
return err
return errors.WithMessage(err, "Failed to call New")
}
// run task list
err = c.Run(ctxt, actions.Screenshot(`http://deutschland.maps.luftdaten.info/`, FolderPath))
if err != nil {
return err
return errors.WithMessage(err, "Failed to call Screenshot")
}
// shutdown chrome
err = c.Shutdown(ctxt)
if err != nil {
return err
return errors.WithMessage(err, "Failed to call Shutdown")
}
log.Println("waiting for headless_shell to exit...")
// wait for chrome to finish
......
module gitlab.com/iotssl/luftdaten_screenshot_tool
require (
github.com/chromedp/cdproto v0.0.0-20181201113921-96cd0ad398e9
github.com/chromedp/chromedp v0.0.0-20181201115416-98d4b0de6e1b
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/pkg/errors v0.8.0
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
)
github.com/chromedp/cdproto v0.0.0-20180713053126-e314dc107013/go.mod h1:C2GPAraqdt1KfZU7aSmx1XUgarNq/3JmxevQkmCjOVs=
github.com/chromedp/cdproto v0.0.0-20181201113921-96cd0ad398e9 h1:pbY4eh/jN0+lOUVhNdr4zLVTX1iU/Xy5SGBUyoQ68eI=
github.com/chromedp/cdproto v0.0.0-20181201113921-96cd0ad398e9/go.mod h1:NcHZYATbiYX27TBzC98mmdw6oG1CGTiRXN+qGlkIzXs=
github.com/chromedp/chromedp v0.0.0-20181201115416-98d4b0de6e1b h1:9CZVl4BX0rgw5k5sUsGl/Yecc+Ub6qCCYAquYwmGzko=
github.com/chromedp/chromedp v0.0.0-20181201115416-98d4b0de6e1b/go.mod h1:83UDY5CKmHrvKLQ6vVU+LVFUcfjOSPNufx8XFWLUYlQ=
github.com/disintegration/imaging v1.4.2 h1:BSVxoYQ2NfLdvIGCDD8GHgBV5K0FCEsc0d/6FxQII3I=
github.com/disintegration/imaging v1.4.2/go.mod h1:9B/deIUIrliYkyMTuXJd6OUFLcrZ2tf+3Qlwnaf/CjU=
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/knq/sysutil v0.0.0-20180306023629-0218e141a794 h1:hgWKTlyruPI7k8W+0FmTMLf+8d2KPxyzTxsfDDQhNp8=
github.com/knq/sysutil v0.0.0-20180306023629-0218e141a794/go.mod h1:BjPj+aVjl9FW/cCGiF3nGh5v+9Gd3VCgBQbod/GlMaQ=
github.com/mailru/easyjson v0.0.0-20180606163543-3fdea8d05856/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment