diff --git a/NOS/cmd/json2txt/json2txt.go b/NOS/cmd/json2txt/json2txt.go index 9f7b3b5..72cc887 100644 --- a/NOS/cmd/json2txt/json2txt.go +++ b/NOS/cmd/json2txt/json2txt.go @@ -11,7 +11,12 @@ import ( "time" ) +type Graph struct { + Items []Item `json:"@graph"` +} + type Item struct { + Type any `json:"@type"` Title string `json:"name"` Text string `json:"articleBody"` Cats []string `json:"articleSection"` @@ -54,8 +59,7 @@ func main() { x(err) fp, err := os.Create("out/" + filename[:len(filename)-5] + ".txt") x(err) - var item Item - x(json.Unmarshal(b, &item)) + item := getItem(b, filename) for _, cat := range item.Cats { x(fmt.Fprintf(fp, "##META text cat = %s\n", fixSpace(cat))) } @@ -68,6 +72,25 @@ func main() { } } +func getItem(b []byte, filename string) Item { + var graph Graph + if json.Unmarshal(b, &graph) == nil { + if graph.Items != nil { + for _, item := range graph.Items { + switch v := item.Type.(type) { + case string: + if v == "NewsArticle" { + return item + } + } + } + } + } + var item Item + x(json.Unmarshal(b, &item), filename) + return item +} + func addEnd(s string) string { s = strings.TrimSpace(s) n := len(s)