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

  1. package main
  2. import (
  3. "WorstCaptcha"
  4. "fmt"
  5. "gopkg.in/gcfg.v1"
  6. "io"
  7. "log"
  8. "net/http"
  9. "os"
  10. )
  11. func main() {
  12. var config WorstCaptcha.Config
  13. var twitter WorstCaptcha.Twitter
  14. // Images directory path
  15. dir, _ := os.Getwd()
  16. imageDir := dir + "/images"
  17. // Parse config file
  18. if err := gcfg.ReadFileInto(&config, "worstcaptcha.gcfg"); err != nil {
  19. fmt.Printf("Config error: %s\n", err)
  20. os.Exit(1)
  21. }
  22. // Get Twitter Client
  23. twitter = WorstCaptcha.NewTwitter(config)
  24. // Get images
  25. for wordlink, _ := range twitter.GetImages() {
  26. fileName := imageDir + "/" + wordlink.Word + ".jpg"
  27. response, err := http.Get(wordlink.Link)
  28. if err != nil {
  29. log.Fatal(err)
  30. }
  31. defer response.Body.Close()
  32. // Open file for writing
  33. file, err := os.Create(fileName)
  34. if err != nil {
  35. log.Fatal(err)
  36. }
  37. // Use io.Copy to just dump the response body to the file. This supports
  38. // huge files
  39. _, err = io.Copy(file, response.Body)
  40. if err != nil {
  41. log.Fatal(err)
  42. }
  43. file.Close()
  44. }
  45. }