nieuw formaat JSON voor NOS
This commit is contained in:
@@ -11,7 +11,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Graph struct {
|
||||||
|
Items []Item `json:"@graph"`
|
||||||
|
}
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
|
Type any `json:"@type"`
|
||||||
Title string `json:"name"`
|
Title string `json:"name"`
|
||||||
Text string `json:"articleBody"`
|
Text string `json:"articleBody"`
|
||||||
Cats []string `json:"articleSection"`
|
Cats []string `json:"articleSection"`
|
||||||
@@ -54,8 +59,7 @@ func main() {
|
|||||||
x(err)
|
x(err)
|
||||||
fp, err := os.Create("out/" + filename[:len(filename)-5] + ".txt")
|
fp, err := os.Create("out/" + filename[:len(filename)-5] + ".txt")
|
||||||
x(err)
|
x(err)
|
||||||
var item Item
|
item := getItem(b, filename)
|
||||||
x(json.Unmarshal(b, &item))
|
|
||||||
for _, cat := range item.Cats {
|
for _, cat := range item.Cats {
|
||||||
x(fmt.Fprintf(fp, "##META text cat = %s\n", fixSpace(cat)))
|
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 {
|
func addEnd(s string) string {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
n := len(s)
|
n := len(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user