func main() { flag.Parse() loadConfig() gorest.RegisterService(new(DreamService)) var err error webClient, err = spicerack.LogIntoSaltyBet(illumEmail, illumPass) if err != nil { fmt.Printf("Error logging into Salty Bet: %v\n", err) } if !*fastcgi { fmt.Println("Running Locally") static := []string{"index", "search", "ds.js", "s.js", "ta.css"} for _, p := range static { http.HandleFunc(fmt.Sprintf("/%s", p), staticPage) } http.Handle("/", gorest.Handle()) fmt.Println(http.ListenAndServe(":9000", nil)) } else { fmt.Println("Running as FastCGI") l, _ := net.Listen("tcp", ":9000") fmt.Println(fcgi.Serve(l, gorest.Handle())) } }
func main() { // load the config file flag.Parse() conf, err := spicerack.GofigFromEnv("ME_CONF") if err != nil { fmt.Printf("%v\nQuitting.\n", err) os.Exit(1) } // inflate settings struct & open db connection settings := &Settings{} conf.Struct("salty", settings) repo, err = spicerack.OpenDb(settings.DbUser, settings.DbPass, settings.DbName) if err != nil { fmt.Printf("Failed to connect to postgres: %v\n", err) os.Exit(1) } defer repo.Close() // reset ELO values if options are present if *resetElo { repo.ResetElo(*eloBase) } // log into saltybet client, err := spicerack.LogIntoSaltyBet(settings.IllumEmail, settings.IllumPword) if err != nil { fmt.Printf("Error logging into saltybet: %v\n", err) os.Exit(1) } // compile a number regex, we'll be using it a lot in parsing numRx, _ = regexp.Compile(`[0-9]+`) // scrape the compendium for updated/new characters fmt.Println("Scraping Roster") if err := getRoster(client); err != nil { fmt.Printf("Failed to scrape roster: %v\n", err) os.Exit(1) } // Get the last n number of tournaments & scrape 'em count := settings.RecentTournamentCount fmt.Printf("Grabbing last %d tournament Ids\n", count) var tourneys []int if *saltTheEarth { tourneys, _ = getAllTournamentIds() } else { tourneys, err = getLatestTournamentIds(client, count) if err != nil { fmt.Printf("Failed to grab tournament IDs: %v\n", err) os.Exit(1) } } for _, tournyId := range tourneys { pageNum := 1 for { fmt.Printf("Processing Tournament #%d, Page #%d\n", tournyId, pageNum) hasNextPage, err := processTournament(client, tournyId, pageNum) if err != nil { fmt.Printf("Failed to parse tournament page: %v\n", err) break } if !hasNextPage { break } fmt.Println() pageNum++ } fmt.Println() } relayToBot(fmt.Sprintf("Scheduled scrape complete, bot information is up to date.")) }