You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1006 B

5 years ago
package main
import (
"WorstCaptcha"
5 years ago
"fmt"
"gopkg.in/gcfg.v1"
5 years ago
"io"
5 years ago
"log"
"net/http"
"os"
5 years ago
)
func main() {
var config WorstCaptcha.Config
var twitter WorstCaptcha.Twitter
5 years ago
// 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)
os.Exit(1)
}
// Get Twitter Client
twitter = WorstCaptcha.NewTwitter(config)
5 years ago
// Get images
for wordlink, _ := range twitter.GetImages() {
5 years ago
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()
}
5 years ago
}