timetable-extension #1

Open
fred.boniface wants to merge 160 commits from timetable-extension into main
3 changed files with 18 additions and 9 deletions
Showing only changes of commit 90bec49826 - Show all commits

View File

@ -5,7 +5,7 @@ import (
)
// Version Constants
const versionNum string = "2024.10.1"
const versionNum string = "2024.10.2"
const versionSuffix string = ""
const Version string = versionNum + versionSuffix

View File

@ -14,21 +14,27 @@ import (
// Process the YAML data to a struct
func processYaml(yamlStr string) (*[]database.PIS, error) {
var pis []PisData
// Define 'container' struct
var pisData struct {
Pis []PisData `yaml:"pis"`
}
// Unmarshal the YAML data into a slice of PisData
err := yaml.Unmarshal([]byte(yamlStr), &pis)
// Unmarshal the YAML data into the structure
err := yaml.Unmarshal([]byte(yamlStr), &pisData)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal YAML: %v", err)
}
// Perform deduplication on the entire pis slice
err = deduplicateCodes(&pis)
err = deduplicateCodes(&pisData.Pis)
if err != nil {
return nil, err
}
documents, err := convertPisForDatabase(&pis)
documents, err := convertPisForDatabase(&pisData.Pis)
if err != nil {
return nil, err
}
return documents, nil
}

View File

@ -9,6 +9,9 @@ import (
"os"
"path/filepath"
"strings"
"git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap"
)
const (
@ -127,7 +130,7 @@ func extractFiles(gzipStream io.Reader, dest string) error {
}
outFile.Close()
default:
fmt.Printf("Unable to handle filetype %c in %s\n", header.Typeflag, header.Name)
log.Warn("Unable to handle filetype", zap.String("Typeflag", string(header.Typeflag)), zap.String("Filename", header.Name))
}
}
return nil
@ -145,7 +148,7 @@ func extractYamlData(dir string) (string, error) {
// Check if the path contains 'pis' and has a .yaml or .yml extension
if strings.Contains(path, "/pis/") && !info.IsDir() &&
(strings.HasSuffix(info.Name(), ".yaml") || strings.HasSuffix(info.Name(), ".yml")) {
fmt.Printf("Processing YAML file in 'pis' directory: %s\n", path)
log.Debug("Processing YAML", zap.String("directory", path))
file, err := os.Open(path)
if err != nil {
@ -179,7 +182,7 @@ func cleanupFiles(paths ...string) {
for _, path := range paths {
err := os.RemoveAll(path)
if err != nil {
fmt.Printf("Error removing %s: %v\n", path, err)
log.Warn("Error removing file", zap.String("path", path), zap.Error(err))
}
}
}