diff --git a/main.go b/main.go index 60b2f16..0e69a69 100644 --- a/main.go +++ b/main.go @@ -10,19 +10,40 @@ import ( "fmt" "os" "path/filepath" + "strconv" ) func main() { - if len(os.Args) != 2 { + if len(os.Args) < 2 { usage(1) } - switch os.Args[1] { + subcommand, args := os.Args[1], os.Args[2:] + + switch subcommand { case "upload": + if len(args) != 0 { + usage(1) + } Upload(Scan()) case "generate": + if len(args) != 0 { + usage(1) + } Generate(Scan()) + case "schedule": + if len(args) != 1 { + usage(1) + } + count, err := strconv.ParseUint(args[0], 10, 32) + must(err) + PrintSchedule(count) case "help", "--help": + if len(args) != 0 { + usage(1) + } usage(0) + default: + usage(1) } } @@ -43,9 +64,10 @@ func fail(msg string, args ...interface{}) { func usage(exitCode int) { fmt.Fprintf(os.Stderr, "Usage:\n\n"+ - " %[1]s upload - Upload all relevant files for one episode to .\n"+ - " %[1]s generate - Generate the c3d2-web news entry XML file for one episode.\n\n"+ - "All relevant files (audios, chapter marks file, shownotes Markdown file) must be in the working directory.\n", + " %[1]s upload - Upload all relevant files for one episode to .\n"+ + " %[1]s generate - Generate the c3d2-web news entry XML file for one episode.\n"+ + " %[1]s schedule - Print the next N airdates.\n\n"+ + "For `upload` and `generate`, all relevant files (audios, chapter marks file, shownotes Markdown file) must be in the working directory.\n", filepath.Base(os.Args[0]), ) os.Exit(exitCode) diff --git a/schedule.go b/schedule.go new file mode 100644 index 0000000..637e4df --- /dev/null +++ b/schedule.go @@ -0,0 +1,43 @@ +/******************************************************************************* +* Copyright 2023 Stefan Majewsky +* SPDX-License-Identifier: GPL-3.0-only +* Refer to the file "LICENSE" for details. +*******************************************************************************/ + +package main + +import ( + "fmt" + "time" +) + +func PrintSchedule(count uint64) { + now := time.Now().UTC() + date := time.Date( + now.Year(), now.Month(), now.Day(), + 12, 0, 0, 0, + now.Location(), + ) + + for printed := uint64(0); printed < count; date = date.AddDate(0, 0, 1) { + if date.Weekday() == time.Tuesday && date.Day() > 21 && date.Day() <= 28 { + printDate(date) + printed++ + } + } +} + +var germanMonths = []string{ + "Januar", "Februar", "März", "April", "Mai", "Juni", + "Juli", "August", "September", "Oktober", "November", "Dezember", +} + +func printDate(t time.Time) { + fmt.Printf( + "%s = %d. %s %d\n", + t.Format(time.DateOnly), + t.Day(), + germanMonths[t.Month()-1], + t.Year(), + ) +}