Fix all the things

This commit is contained in:
kolaente 2020-09-15 18:21:54 +02:00
parent 736da4c326
commit a8161270fc
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 9 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
.idea/
qrcode-bulk
*.txt
qrcodes/

12
main.go
View File

@ -12,7 +12,7 @@ import (
)
func handleErr(format string, args ...interface{}) {
fmt.Printf(format, args)
fmt.Printf(format, args...)
os.Exit(1)
}
@ -34,7 +34,7 @@ func main() {
if err != nil {
handleErr("Could not get current dir: %s", err)
}
if workingDir == "" {
if workingDir == "" || workingDir == "\n" || workingDir == "\n\r" {
workingDir = cwd
}
@ -44,12 +44,12 @@ func main() {
}
// 2. Get Files
files, err := filepath.Glob(path.Join(workingDir, "*.txt"))
files, err := filepath.Glob(workingDir + "/*.txt")
if err != nil {
handleErr("Could not get files: %s", err)
}
fmt.Printf("Generating %d QR Codes...\n\r", len(files))
fmt.Printf("Generating %d QR Codes from files in %s...\n\r", len(files), workingDir)
for _, file := range files {
f, err := os.Open(file)
@ -59,12 +59,12 @@ func main() {
if !strings.HasSuffix(f.Name(), ".txt") {
continue
}
content, err := ioutil.ReadFile(path.Join(workingDir, f.Name()))
content, err := ioutil.ReadFile(file)
if err != nil {
handleErr("Could not open file '%s': %s", f.Name(), err)
}
// 3. Generate QR-Codes and save
err = qrcode.WriteFile(string(content), qrcode.High, 1024, path.Join(outPath, strings.TrimSuffix(f.Name(), path.Ext(file))))
err = qrcode.WriteFile(string(content), qrcode.Low, 2048, path.Join(outPath, strings.TrimSuffix(path.Base(f.Name()), path.Ext(file)))+".png")
if err != nil {
handleErr("Could not create qr code for file '%s': %s", f.Name(), err)
}