diff --git a/.gitignore b/.gitignore index 07d0408..dc90bc2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ vendor out config.yaml .DS_Store +results diff --git a/build/build.sh b/build/build.sh deleted file mode 100755 index e319d6e..0000000 --- a/build/build.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/bash -# -# GoLang cross-compile snippet for Go 1.6+ based loosely on Dave Chaney's cross-compile script: -# http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go -# -# To use: -# -# $ cd ~/path-to/my-awesome-project -# $ go-build-all -# -# Features: -# -# * Cross-compiles to multiple machine types and architectures. -# * Uses the current directory name as the output name... -# * ...unless you supply an source file: $ go-build-all main.go -# * Windows binaries are named .exe. -# * ARM v5, v6, v7 and v8 (arm64) support -# -# ARM Support: -# -# You must read https://github.com/golang/go/wiki/GoArm for the specifics of running -# Linux/BSD-style kernels and what kernel modules are needed for the target platform. -# While not needed for cross-compilation of this script, you're users will need to ensure -# the correct modules are included. -# -# Requirements: -# -# * GoLang 1.6+ (for mips and ppc), 1.5 for non-mips/ppc. -# * CD to directory of the binary you are compiling. $PWD is used here. -# -# For 1.4 and earlier, see http://dave.cheney.net/2012/09/08/an-introduction-to-cross-compilation-with-go -# - -# This PLATFORMS list is refreshed after every major Go release. -# Though more platforms may be supported (freebsd/386), they have been removed -# from the standard ports/downloads and therefore removed from this list. -# -PLATFORMS="darwin/amd64" # amd64 only as of go1.5 -PLATFORMS="$PLATFORMS windows/amd64 windows/386" # arm compilation not available for Windows -PLATFORMS="$PLATFORMS linux/amd64 linux/386" -PLATFORMS="$PLATFORMS linux/ppc64 linux/ppc64le" -PLATFORMS="$PLATFORMS linux/mips64 linux/mips64le" # experimental in go1.6 -PLATFORMS="$PLATFORMS freebsd/amd64" -PLATFORMS="$PLATFORMS netbsd/amd64" # amd64 only as of go1.6 -PLATFORMS="$PLATFORMS openbsd/amd64" # amd64 only as of go1.6 -PLATFORMS="$PLATFORMS dragonfly/amd64" # amd64 only as of go1.5 -PLATFORMS="$PLATFORMS plan9/amd64 plan9/386" # as of go1.4 -PLATFORMS="$PLATFORMS solaris/amd64" # as of go1.3 - -# ARMBUILDS lists the platforms that are currently supported. From this list -# we generate the following architectures: -# -# ARM64 (aka ARMv8) <- only supported on linux and darwin builds (go1.6) -# ARMv7 -# ARMv6 -# ARMv5 -# -# Some words of caution from the master: -# -# @dfc: you'll have to use gomobile to build for darwin/arm64 [and others] -# @dfc: that target expects that you're bulding for a mobile phone -# @dfc: iphone 5 and below, ARMv7, iphone 3 and below ARMv6, iphone 5s and above arm64 -# -PLATFORMS_ARM="linux freebsd netbsd" - -############################################################## -# Shouldn't really need to modify anything below this line. # -############################################################## - -type setopt >/dev/null 2>&1 - -SCRIPT_NAME=`basename "$0"` -FAILURES="" -SOURCE_FILE=`echo $@ | sed 's/\.go//'` -CURRENT_DIRECTORY=${PWD##*/} -OUTPUT=${SOURCE_FILE:-$CURRENT_DIRECTORY} # if no src file given, use current dir name -OUTDIR="bin" - -for PLATFORM in $PLATFORMS; do - GOOS=${PLATFORM%/*} - GOARCH=${PLATFORM#*/} - BIN_FILENAME="${OUTDIR}/${OUTPUT}-${GOOS}-${GOARCH}" - if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi - CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BIN_FILENAME} $@" - echo "${CMD}" - eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" -done - -# ARM builds -if [[ $PLATFORMS_ARM == *"linux"* ]]; then - CMD="GOOS=linux GOARCH=arm64 go build -o ${OUTPUT}-linux-arm64 $@" - echo "${CMD}" - eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" -fi -for GOOS in $PLATFORMS_ARM; do - GOARCH="arm" - # build for each ARM version - for GOARM in 7 6 5; do - BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}${GOARM}" - CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build -o ${BIN_FILENAME} $@" - echo "${CMD}" - eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}" - done -done - -# eval errors -if [[ "${FAILURES}" != "" ]]; then - echo "" - echo "${SCRIPT_NAME} failed on: ${FAILURES}" - exit 1 -fi diff --git a/config.go b/config.go index 6dd79b0..cffc022 100644 --- a/config.go +++ b/config.go @@ -38,7 +38,10 @@ type Config struct { OutDir string `yaml:"-"` ParallelDownloads int `yaml:"parallelDownloads"` MaxWaitTime int `yaml:"waitTime"` - Rate int `yaml:"rate"` + Rate int `yaml:"rate"` + IncludeSlugs map[string]bool `yaml:"-"` + ExcludeSlugs map[string]bool `yaml:"-"` + PrintSlugs bool `yaml:"-"` } func ParseConfig(filename string) (*Config, error) { diff --git a/include.txt b/include.txt new file mode 100644 index 0000000..ceead85 --- /dev/null +++ b/include.txt @@ -0,0 +1,2 @@ +silent-addition +the-magic-mirror-2-1 diff --git a/main.go b/main.go index 88315c1..2af537b 100644 --- a/main.go +++ b/main.go @@ -25,9 +25,12 @@ package main import ( + "bufio" "flag" + "fmt" "os" "path/filepath" + "strings" "sync" "time" @@ -70,8 +73,25 @@ func exec(cfg *Config) { log.Fatal(err) } + if cfg.PrintSlugs { + for _, q := range qs.Models { + fmt.Println(q.Slug) + } + return + } + var subs = make(map[string]SubmissionMap) + for _, q := range qs.Models { + if len(cfg.IncludeSlugs) > 0 && !cfg.IncludeSlugs[q.Slug] { + log.Debugf("skipping challenge %s (not in include list)", q.Slug) + continue + } + if len(cfg.ExcludeSlugs) > 0 && cfg.ExcludeSlugs[q.Slug] { + log.Infof("skipping challenge %s (in exclude list)", q.Slug) + continue + } + s, err := GetAllSubmissions(client, cfg, q.Slug) if err != nil { log.Fatalf("error fetching submissions, %v", err) @@ -146,10 +166,34 @@ func exec(cfg *Config) { log.Info("finished executing") } +func readSlugsFromFile(path string) (map[string]bool, error) { + file, err := os.Open(path) + if err != nil { + return nil, err + } + defer file.Close() + + slugs := make(map[string]bool) + scanner := bufio.NewScanner(file) + for scanner.Scan() { + text := strings.TrimSpace(scanner.Text()) + if text != "" { + slugs[text] = true + } + } + return slugs, scanner.Err() +} + func main() { var configPath string + var printSlugs bool + var includeFile string + var excludeFile string flag.StringVar(&configPath, "config", "config.yaml", "Provide config for the tool") + flag.BoolVar(&printSlugs, "print-slugs", false, "Print all challenge slugs and exit") + flag.StringVar(&includeFile, "include", "", "Path to file containing slugs to include (one per line)") + flag.StringVar(&excludeFile, "exclude", "", "Path to file containing slugs to exclude (one per line)") flag.Parse() cfg, err := ParseConfig(configPath) @@ -157,6 +201,24 @@ func main() { log.Fatal(err) } + cfg.PrintSlugs = printSlugs + + if includeFile != "" { + slugs, err := readSlugsFromFile(includeFile) + if err != nil { + log.Fatalf("error reading include file: %v", err) + } + cfg.IncludeSlugs = slugs + } + + if excludeFile != "" { + slugs, err := readSlugsFromFile(excludeFile) + if err != nil { + log.Fatalf("error reading exclude file: %v", err) + } + cfg.ExcludeSlugs = slugs + } + // create output directory with current time cfg.OutDir = filepath.Join(filepath.FromSlash(cfg.Output), time.Now().Format("2006-01-02-15-04"))