Adjustments to PIS Module

This commit is contained in:
Fred Boniface 2024-10-24 20:39:24 +01:00
parent 52732d2ae1
commit 90bec49826
3 changed files with 18 additions and 9 deletions

View File

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

View File

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

View File

@ -9,6 +9,9 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap"
) )
const ( const (
@ -127,7 +130,7 @@ func extractFiles(gzipStream io.Reader, dest string) error {
} }
outFile.Close() outFile.Close()
default: 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 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 // Check if the path contains 'pis' and has a .yaml or .yml extension
if strings.Contains(path, "/pis/") && !info.IsDir() && if strings.Contains(path, "/pis/") && !info.IsDir() &&
(strings.HasSuffix(info.Name(), ".yaml") || strings.HasSuffix(info.Name(), ".yml")) { (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) file, err := os.Open(path)
if err != nil { if err != nil {
@ -179,7 +182,7 @@ func cleanupFiles(paths ...string) {
for _, path := range paths { for _, path := range paths {
err := os.RemoveAll(path) err := os.RemoveAll(path)
if err != nil { if err != nil {
fmt.Printf("Error removing %s: %v\n", path, err) log.Warn("Error removing file", zap.String("path", path), zap.Error(err))
} }
} }
} }