Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ vendor
out
config.yaml
.DS_Store
results
111 changes: 0 additions & 111 deletions build/build.sh

This file was deleted.

5 changes: 4 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions include.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
silent-addition
the-magic-mirror-2-1
62 changes: 62 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
package main

import (
"bufio"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -146,17 +166,59 @@ 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)
if err != nil {
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"))

Expand Down