-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/PuerkitoBio/goquery" | ||
version = "1.4.1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
) | ||
|
||
var ( | ||
pairsFlag = flag.String("p", "", "") | ||
out = flag.String("out", "", "") | ||
) | ||
|
||
const ( | ||
basePath = "http://www.cnj.jus.br" | ||
remuneracaoPath = "http://www.cnj.jus.br/transparencia/remuneracao-dos-magistrados/remuneracao-" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
pairs := strings.Split(*pairsFlag, ",") | ||
var wg sync.WaitGroup | ||
for _, p := range pairs { | ||
remuneracaoURL := fmt.Sprintf("%s%s", remuneracaoPath, p) | ||
doc, err := goquery.NewDocument(remuneracaoURL) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
doc.Find("td").Each(func(index int, item *goquery.Selection) { | ||
linkTag := item.Find("a") | ||
link, _ := linkTag.Attr("href") | ||
if strings.HasSuffix(link, "xls") || strings.HasSuffix(link, "xlsx") { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
dLink := fmt.Sprintf("%s%s", basePath, link) | ||
resp, err := http.Get(dLink) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer resp.Body.Close() | ||
b, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
outPath := filepath.Join(*out, fmt.Sprintf("%s-%s", p, filepath.Base(dLink))) | ||
f, err := os.Create(outPath) | ||
defer f.Close() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
w := bufio.NewWriter(f) | ||
w.Write(b) | ||
w.Flush() | ||
fmt.Printf("%s downloaded to %s\n", dLink, outPath) | ||
}() | ||
} | ||
}) | ||
} | ||
wg.Wait() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.