1

Colorized output

This commit is contained in:
Alex Yatskov 2015-09-18 17:26:37 +09:00
parent dfecf65ba9
commit c3929aff1d
2 changed files with 8 additions and 2 deletions

View File

@ -36,6 +36,7 @@ import (
"strings" "strings"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/fatih/color"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )
@ -274,17 +275,21 @@ func main() {
webcachePath := flag.String("webcache", "cache/webcache", "web data cache") webcachePath := flag.String("webcache", "cache/webcache", "web data cache")
flag.Parse() flag.Parse()
log.Print(color.BlueString("scraping data..."))
reviews, err := scrapeData(*urlsPath, *geocachePath, *webcachePath) reviews, err := scrapeData(*urlsPath, *geocachePath, *webcachePath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Print(color.BlueString("collating data..."))
restaurants := collateData(reviews) restaurants := collateData(reviews)
log.Print(color.BlueString("computing station data..."))
if err := computeStnData(restaurants, *stationsPath); err != nil { if err := computeStnData(restaurants, *stationsPath); err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Print(color.BlueString("saving data..."))
if err := dumpData(*dbPath, restaurants); err != nil { if err := dumpData(*dbPath, restaurants); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -28,6 +28,7 @@ import (
"sync" "sync"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/fatih/color"
) )
type feature struct { type feature struct {
@ -159,10 +160,10 @@ func scrape(url string, scr scraper) ([]review, error) {
defer wg.Done() defer wg.Done()
for rev := range out { for rev := range out {
if rev.err == nil { if rev.err == nil {
log.Printf("SUCCESS: %s", rev.name) log.Print(color.GreenString(rev.name))
reviews = append(reviews, rev) reviews = append(reviews, rev)
} else { } else {
log.Printf("FAIL: %s", rev.name) log.Printf("%s (%s)", color.YellowString(rev.name), color.RedString(rev.err.Error()))
} }
} }
}() }()