|
| 1 | +# Advent of Code helper |
| 2 | + |
| 3 | +> You can also get the [JSON] for this private leaderboard. Please |
| 4 | +> don't make frequent automated requests to this service - avoid |
| 5 | +> sending requests more often than once every 15 minutes (900 seconds). |
| 6 | +> If you do this from a script, you'll have to provide your session |
| 7 | +> cookie in the request; a fresh session cookie lasts for about a month. |
| 8 | +> Timestamps use Unix time. |
| 9 | +> |
| 10 | +> Source: adventofcode.com |
| 11 | +
|
| 12 | +```go |
| 13 | +targetDir := fmt.Sprintf("input/day%02d", dayNumber) |
| 14 | +targetFile := fmt.Sprintf("%s/input", targetDir) |
| 15 | + |
| 16 | +ensurePath(targetDir) |
| 17 | + |
| 18 | +client := aoc.NewClient(os.Getenv("AOC_SESSION")) |
| 19 | + |
| 20 | +err := client.DownloadAndSaveInput(currentYear, dayNumber, targetFile) |
| 21 | +if err != nil { |
| 22 | + logrus.Fatal(err.Error()) |
| 23 | + |
| 24 | + return |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +## Submit a solution |
| 29 | + |
| 30 | +```go |
| 31 | +client := aoc.NewClient(os.Getenv("AOC_SESSION")) |
| 32 | + |
| 33 | +valid, err := client.SubmitSolution(currentYear, dayNumber, partNumber, solution) |
| 34 | +if err != nil { |
| 35 | + fmt.Printf("%s\n", err.Error()) |
| 36 | + |
| 37 | + return |
| 38 | +} |
| 39 | + |
| 40 | +if valid { |
| 41 | + fmt.Println("Done \\o/") |
| 42 | +} else { |
| 43 | + fmt.Println("Something is wrong :(") |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +## Generate file/directory structure from template |
| 48 | + |
| 49 | +Note: All file will be rendered with `.tmpl` extension |
| 50 | + and all directory will be created where there is at least |
| 51 | + one `.tmpl` file. |
| 52 | + |
| 53 | +```go |
| 54 | +type templateVariables struct { |
| 55 | + Day int |
| 56 | + Root string |
| 57 | +} |
| 58 | + |
| 59 | +err := aoc.Scaffold( |
| 60 | + templateDir, |
| 61 | + fmt.Sprintf("days/day%02d", dayNumber), |
| 62 | + templateVariables{ |
| 63 | + Day: dayNumber, |
| 64 | + Root: packageRoot, |
| 65 | + }, |
| 66 | +) |
| 67 | +if err != nil { |
| 68 | + logrus.Errorln(err) |
| 69 | +} |
| 70 | +``` |
0 commit comments