|
|
|
@ -5,12 +5,19 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"gopkg.in/gcfg.v1"
|
|
|
|
|
"os"
|
|
|
|
|
"net/http"
|
|
|
|
|
"log"
|
|
|
|
|
"io"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
var config WorstCaptcha.Config
|
|
|
|
|
var twitter WorstCaptcha.Twitter
|
|
|
|
|
|
|
|
|
|
// Images directory path
|
|
|
|
|
dir, _ := os.Getwd()
|
|
|
|
|
imageDir := dir + "/images"
|
|
|
|
|
|
|
|
|
|
// Parse config file
|
|
|
|
|
if err := gcfg.ReadFileInto(&config, "worstcaptcha.gcfg"); err != nil {
|
|
|
|
|
fmt.Printf("Config error: %s\n", err)
|
|
|
|
@ -22,7 +29,28 @@ func main() {
|
|
|
|
|
|
|
|
|
|
// Get images
|
|
|
|
|
for wordlink, _ := range twitter.GetImages() {
|
|
|
|
|
fmt.Println("===================")
|
|
|
|
|
fmt.Println(wordlink)
|
|
|
|
|
fileName := imageDir + "/" + wordlink.Word + ".jpg"
|
|
|
|
|
|
|
|
|
|
response, err := http.Get(wordlink.Link)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer response.Body.Close()
|
|
|
|
|
|
|
|
|
|
// Open file for writing
|
|
|
|
|
file, err := os.Create(fileName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use io.Copy to just dump the response body to the file. This supports
|
|
|
|
|
// huge files
|
|
|
|
|
_, err = io.Copy(file, response.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.Close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|