timetable-extension #1

Open
fred.boniface wants to merge 154 commits from timetable-extension into main
2 changed files with 32 additions and 2 deletions
Showing only changes of commit 259f514b3d - Show all commits

View File

@ -112,7 +112,7 @@ func debugWriteFile(header *upstreamApi.JsonTimetableV1, schedule *[]upstreamApi
if helpers.Runtime == "debug" { if helpers.Runtime == "debug" {
log.Msg.Debug("Writing CIF Header and Schedule elements to file") log.Msg.Debug("Writing CIF Header and Schedule elements to file")
filepath := "./cif_debug_data/" 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{}{ data, err := json.MarshalIndent(map[string]interface{}{
"header": header, "header": header,
@ -129,9 +129,28 @@ func debugWriteFile(header *upstreamApi.JsonTimetableV1, schedule *[]upstreamApi
return return
} }
writeErr := os.WriteFile(filepath+filename, data, 0777) writeErr := os.WriteFile(filepath+filename+".json", data, 0777)
if writeErr != nil { if writeErr != nil {
log.Msg.Error("Error writing debug file to disk", zap.Error(writeErr)) 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)) 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 // Parse CIF file
parsed, err := parseCifData(data) parsed, err := parseCifData(data)
if err != nil { 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)) log.Msg.Error("Error fetching CIF update", zap.Error(err))
return err return err
} }
// If debug mode is on, call debugWriteDownload
if helpers.Runtime == "debug" {
debugWriteDownload(&data)
}
// Parse CIF file // Parse CIF file
parsed, err := parseCifData(data) parsed, err := parseCifData(data)
if err != nil { if err != nil {