add `schedule` subcommand
This commit is contained in:
parent
a1c1a08ff7
commit
b76992e395
32
main.go
32
main.go
|
@ -10,19 +10,40 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) < 2 {
|
||||||
usage(1)
|
usage(1)
|
||||||
}
|
}
|
||||||
switch os.Args[1] {
|
subcommand, args := os.Args[1], os.Args[2:]
|
||||||
|
|
||||||
|
switch subcommand {
|
||||||
case "upload":
|
case "upload":
|
||||||
|
if len(args) != 0 {
|
||||||
|
usage(1)
|
||||||
|
}
|
||||||
Upload(Scan())
|
Upload(Scan())
|
||||||
case "generate":
|
case "generate":
|
||||||
|
if len(args) != 0 {
|
||||||
|
usage(1)
|
||||||
|
}
|
||||||
Generate(Scan())
|
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":
|
case "help", "--help":
|
||||||
|
if len(args) != 0 {
|
||||||
|
usage(1)
|
||||||
|
}
|
||||||
usage(0)
|
usage(0)
|
||||||
|
default:
|
||||||
|
usage(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +64,10 @@ func fail(msg string, args ...interface{}) {
|
||||||
func usage(exitCode int) {
|
func usage(exitCode int) {
|
||||||
fmt.Fprintf(os.Stderr,
|
fmt.Fprintf(os.Stderr,
|
||||||
"Usage:\n\n"+
|
"Usage:\n\n"+
|
||||||
" %[1]s upload - Upload all relevant files for one episode to <sftp://ftp.c3d2.de>.\n"+
|
" %[1]s upload - Upload all relevant files for one episode to <sftp://ftp.c3d2.de>.\n"+
|
||||||
" %[1]s generate - Generate the c3d2-web news entry XML file for one episode.\n\n"+
|
" %[1]s generate - Generate the c3d2-web news entry XML file for one episode.\n"+
|
||||||
"All relevant files (audios, chapter marks file, shownotes Markdown file) must be in the working directory.\n",
|
" %[1]s schedule <N> - 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]),
|
filepath.Base(os.Args[0]),
|
||||||
)
|
)
|
||||||
os.Exit(exitCode)
|
os.Exit(exitCode)
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright 2023 Stefan Majewsky <majewsky@gmx.net>
|
||||||
|
* 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(),
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue