Add function to write full CIF download to filesystem
All checks were successful
Go Test / test (push) Successful in 37s

This commit is contained in:
Fred Boniface 2024-04-09 20:55:26 +01:00
parent 2c34c529e1
commit 259f514b3d
2 changed files with 32 additions and 2 deletions

View File

@ -112,7 +112,7 @@ func debugWriteFile(header *upstreamApi.JsonTimetableV1, schedule *[]upstreamApi
if helpers.Runtime == "debug" {
log.Msg.Debug("Writing CIF Header and Schedule elements to file")
filepath := "./cif_debug_data/"
filename := time.Now().In(londonTimezone).Format("2006-01-02_15:04:05_CIF")
filename := time.Now().In(londonTimezone).Format("2006-01-02_15:04:05_ParsedCIF")
data, err := json.MarshalIndent(map[string]interface{}{
"header": header,
@ -129,9 +129,28 @@ func debugWriteFile(header *upstreamApi.JsonTimetableV1, schedule *[]upstreamApi
return
}
writeErr := os.WriteFile(filepath+filename, data, 0777)
writeErr := os.WriteFile(filepath+filename+".json", data, 0777)
if writeErr != nil {
log.Msg.Error("Error writing debug file to disk", zap.Error(writeErr))
}
}
}
func debugWriteDownload(input *[]byte) {
if helpers.Runtime == "debug" {
log.Msg.Debug("Writing CIF Download to file")
filepath := "./cif_debug_data/"
filename := time.Now().In(londonTimezone).Format("2006-01-02_15:04:05_RawCIF")
err := os.MkdirAll(filepath, 0777)
if err != nil {
log.Msg.Error("Error creating directory", zap.Error(err))
return
}
err = os.WriteFile(filepath+filename+".jsonl", *input, 0777)
if err != nil {
log.Msg.Error("Error writing debug file to disk", zap.Error(err))
}
}
}

View File

@ -25,6 +25,11 @@ func runCifFullDownload(cfg *helpers.Configuration) error {
log.Msg.Error("Error downloading CIF data", zap.Error(err))
}
// If debug mode is on, call debugWriteDownload
if helpers.Runtime == "debug" {
debugWriteDownload(&data)
}
// Parse CIF file
parsed, err := parseCifData(data)
if err != nil {
@ -69,6 +74,12 @@ func runCifUpdateDownload(cfg *helpers.Configuration, metadata *dbAccess.CifMeta
log.Msg.Error("Error fetching CIF update", zap.Error(err))
return err
}
// If debug mode is on, call debugWriteDownload
if helpers.Runtime == "debug" {
debugWriteDownload(&data)
}
// Parse CIF file
parsed, err := parseCifData(data)
if err != nil {