added interactive component to control title and filename
This commit is contained in:
17
go.mod
17
go.mod
@@ -3,7 +3,24 @@ module stugago-vvlist
|
||||
go 1.25.8
|
||||
|
||||
require (
|
||||
charm.land/bubbletea/v2 v2.0.2 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.4.1 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.6 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.9.0 // indirect
|
||||
github.com/clipperhouse/stringish v0.1.1 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.19 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect
|
||||
github.com/pkg/errors v0.8.1 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/signintech/gopdf v0.36.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
)
|
||||
|
||||
34
go.sum
34
go.sum
@@ -1,6 +1,40 @@
|
||||
charm.land/bubbletea/v2 v2.0.2 h1:4CRtRnuZOdFDTWSff9r8QFt/9+z6Emubz3aDMnf/dx0=
|
||||
charm.land/bubbletea/v2 v2.0.2/go.mod h1:3LRff2U4WIYXy7MTxfbAQ+AdfM3D8Xuvz2wbsOD9OHQ=
|
||||
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
|
||||
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 h1:eyFRbAmexyt43hVfeyBofiGSEmJ7krjLOYt/9CF5NKA=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8/go.mod h1:SQpCTRNBtzJkwku5ye4S3HEuthAlGy2n9VXZnWkEW98=
|
||||
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
|
||||
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
|
||||
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
|
||||
github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
|
||||
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
|
||||
github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
|
||||
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
|
||||
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
|
||||
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 h1:zyWXQ6vu27ETMpYsEMAsisQ+GqJ4e1TPvSNfdOPF0no=
|
||||
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/signintech/gopdf v0.36.0 h1:/7gPwoLtlNv5tPNpYuo3T3z0mWgo62pTrCvVNAiOo2Q=
|
||||
github.com/signintech/gopdf v0.36.0/go.mod h1:d23eO35GpEliSrF22eJ4bsM3wVeQJTjXTHq5x5qGKjA=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
|
||||
88
main.go
88
main.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -10,13 +11,40 @@ import (
|
||||
"github.com/signintech/gopdf"
|
||||
)
|
||||
|
||||
const title string = "Teilnahmeliste der StugA Lehramt GO-Vollversammlung 07.04.2026"
|
||||
|
||||
func main() {
|
||||
// Prepare data
|
||||
file, err := os.Open("list.csv")
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
fmt.Print("Moin! Dieses kleine Tool erstellt dir eine Teilnahmeliste als PDF, welche du an den AStA schicken kannst, um nach einer Vollversammlung den StugA bestätigen zu lassen.\n\n")
|
||||
fmt.Print("Wahrscheinlich/hoffentlich habt ihr für die Teilnahmeliste eine Umfrage auf Nextcloud erstellt, in welcher sich Leute eintragen konnten. Falls dem so ist -- perfekt! Exportiere die Daten aus Nextcloud im CSV-Format und packe sie in den selben Ordner, in welchem auch dieses Programm liegt.\n\n")
|
||||
fmt.Println("Gib bitte jetzt den Namen der Datei ein, z.B. 'liste.csv':")
|
||||
|
||||
scanner.Scan()
|
||||
err := scanner.Err()
|
||||
if err != nil {
|
||||
log.Fatalln("Error while reading file: " + err.Error())
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
fileName := scanner.Text()
|
||||
|
||||
fmt.Println("Danke! Jetzt brauche ich noch einen Titel, wie z.B. 'Teilnahmeliste der StugA Lehramt GO-Vollversammlung 01.01.2026':")
|
||||
|
||||
scanner.Scan()
|
||||
err2 := scanner.Err()
|
||||
if err2 != nil {
|
||||
log.Fatalln(err2.Error())
|
||||
}
|
||||
title := scanner.Text()
|
||||
|
||||
fmt.Println("Deine Datei wird erstellt...")
|
||||
|
||||
createPdf(fileName, title)
|
||||
|
||||
fmt.Println("Die Datei wurde erstellt! Das Programm schließt sich jetzt.")
|
||||
}
|
||||
|
||||
func createPdf(fileName, title string) {
|
||||
// Prepare data
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
log.Fatalln("Fehler beim Öffnen der Datei: " + err.Error())
|
||||
}
|
||||
|
||||
reader := csv.NewReader(file)
|
||||
@@ -24,11 +52,9 @@ func main() {
|
||||
records, errRecords := reader.ReadAll()
|
||||
|
||||
if errRecords != nil {
|
||||
log.Fatalln("Error while parsing file: " + errRecords.Error())
|
||||
log.Fatalln("Fehler beim Auslesen der Datei: " + errRecords.Error())
|
||||
}
|
||||
|
||||
log.Println("hey")
|
||||
|
||||
defer file.Close()
|
||||
|
||||
// Prepare document
|
||||
@@ -52,13 +78,9 @@ func main() {
|
||||
record[3],
|
||||
record[5],
|
||||
})
|
||||
// if index%31 == 0 {
|
||||
// pdf.AddPage()
|
||||
// }
|
||||
}
|
||||
|
||||
iterations := math.Ceil(float64(len(tableEntries)) / 31.0)
|
||||
fmt.Println(iterations)
|
||||
|
||||
for i := 0; i < int(iterations); i += 1 {
|
||||
// create each page here
|
||||
@@ -95,48 +117,6 @@ func main() {
|
||||
pdf.Cell(nil, fmt.Sprintf("%d", int(i+1)))
|
||||
}
|
||||
|
||||
// table.SetTableStyle(gopdf.CellStyle{
|
||||
// BorderStyle: gopdf.BorderStyle{
|
||||
// Top: true,
|
||||
// Left: true,
|
||||
// Bottom: true,
|
||||
// Right: true,
|
||||
// Width: 1.0,
|
||||
// },
|
||||
// FillColor: gopdf.RGBColor{R: 255, G: 255, B: 255},
|
||||
// TextColor: gopdf.RGBColor{R: 0, G: 0, B: 0},
|
||||
// FontSize: 10,
|
||||
// })
|
||||
|
||||
// // Set the style for table header
|
||||
// table.SetHeaderStyle(gopdf.CellStyle{
|
||||
// BorderStyle: gopdf.BorderStyle{
|
||||
// Top: true,
|
||||
// Left: true,
|
||||
// Bottom: true,
|
||||
// Right: true,
|
||||
// Width: 2.0,
|
||||
// RGBColor: gopdf.RGBColor{R: 100, G: 150, B: 255},
|
||||
// },
|
||||
// FillColor: gopdf.RGBColor{R: 255, G: 200, B: 200},
|
||||
// TextColor: gopdf.RGBColor{R: 255, G: 100, B: 100},
|
||||
// Font: "font2",
|
||||
// FontSize: 12,
|
||||
// })
|
||||
|
||||
// table.SetCellStyle(gopdf.CellStyle{
|
||||
// BorderStyle: gopdf.BorderStyle{
|
||||
// Right: true,
|
||||
// Bottom: true,
|
||||
// Width: 0.5,
|
||||
// RGBColor: gopdf.RGBColor{R: 0, G: 0, B: 0},
|
||||
// },
|
||||
// FillColor: gopdf.RGBColor{R: 255, G: 255, B: 255},
|
||||
// TextColor: gopdf.RGBColor{R: 0, G: 0, B: 0},
|
||||
// Font: "font1",
|
||||
// FontSize: 10,
|
||||
// })
|
||||
|
||||
// Finish document
|
||||
pdf.WritePdf("vvliste.pdf")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user