nieuw formaat JSON voor NOS
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user