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.
 
 
 

66 lines
1.2 KiB

  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file or at
  5. // https://developers.google.com/open-source/licenses/bsd.
  6. package main
  7. import (
  8. "fmt"
  9. "io/ioutil"
  10. "log"
  11. "os"
  12. "strings"
  13. "github.com/garyburd/redigo/redis"
  14. "github.com/golang/gddo/database"
  15. )
  16. var crawlCommand = &command{
  17. name: "crawl",
  18. run: crawl,
  19. usage: "crawl [new]",
  20. }
  21. func crawl(c *command) {
  22. if len(c.flag.Args()) > 1 {
  23. c.printUsage()
  24. os.Exit(1)
  25. }
  26. db, err := database.New()
  27. if err != nil {
  28. log.Fatal(err)
  29. }
  30. if len(c.flag.Args()) == 1 {
  31. p, err := ioutil.ReadFile(c.flag.Args()[0])
  32. if err != nil {
  33. log.Fatal(err)
  34. }
  35. for _, p := range strings.Fields(string(p)) {
  36. db.AddNewCrawl(p)
  37. }
  38. }
  39. conn := db.Pool.Get()
  40. defer conn.Close()
  41. paths, err := redis.Strings(conn.Do("SMEMBERS", "newCrawl"))
  42. if err != nil {
  43. log.Fatal(err)
  44. }
  45. fmt.Println("NEW")
  46. for _, path := range paths {
  47. fmt.Println(path)
  48. }
  49. paths, err = redis.Strings(conn.Do("SMEMBERS", "badCrawl"))
  50. if err != nil {
  51. log.Fatal(err)
  52. }
  53. fmt.Println("BAD")
  54. for _, path := range paths {
  55. fmt.Println(path)
  56. }
  57. }