amuse.git

commit 311a054f2c4bfe9695a8a2feda1525548b8b55ac

Author: Adam <git@apiote.tk>

get article title for books from Inventaire

 datastructure/book.go | 4 +++-
 inventaire/book.go | 16 ++++++++--------


diff --git a/datastructure/book.go b/datastructure/book.go
index 5eafb73682580254e4df08dcc025aa39acaeb739..8b4e0b201d0a48fad7cd32a5583be0c26617fc44 100644
--- a/datastructure/book.go
+++ b/datastructure/book.go
@@ -40,7 +40,9 @@ 	return b.Article
 }
 
 func (b *Book) SetDescription(description string) {
-	b.Description = description
+	if b.Description == "" {
+		b.Description = description
+	}
 }
 
 func (b *Book) GetItemInfo() ItemInfo {




diff --git a/inventaire/book.go b/inventaire/book.go
index 3f832f4a005b52f7769b743dd93a2c2d05a61ca2..ca0f56cb3c9fcac14e0d7c48b5fd2e4eb7a6a6e6 100644
--- a/inventaire/book.go
+++ b/inventaire/book.go
@@ -41,16 +41,16 @@ 	result.Request = httpRequest
 	return gott.Tuple(args), err
 }
 
-func findByTag(haystack map[string]string, tag string) string {
+func findByTag(haystack map[string]string, tag, suffix string) string {
 	tag = strings.ToLower(tag)
-	result := haystack[tag]
+	result := haystack[tag+suffix]
 	if result == "" {
 		tag = strings.Split(tag, "-")[0]
-		result = haystack[tag]
+		result = haystack[tag+suffix]
 	}
 	if result == "" {
 		tag = "en"
-		result = haystack[tag]
+		result = haystack[tag+suffix]
 	}
 	return result
 }
@@ -70,9 +70,9 @@ 		Name: "Inventaire",
 	}
 	book.Source = append(book.Source, source)
 	book.Authors = append(book.Authors, response.Entities[id].Claims["wdt:P50"]...)
-	book.Title = findByTag(response.Entities[id].Labels, language)
-	// todo book.Article from Sitelinks[tag+"wiki"]
-	book.Description = findByTag(response.Entities[id].Descriptions, language)
+	book.Title = findByTag(response.Entities[id].Labels, language, "")
+	book.Article = findByTag(response.Entities[id].Sitelinks, language, "wiki")
+	book.Description = findByTag(response.Entities[id].Descriptions, language, "")
 	result.Result = book
 	return gott.Tuple(args), err
 }
@@ -118,7 +118,7 @@ 	err := json.Unmarshal(result.Body, response)
 	ids := strings.Split(id, "|")
 	result.Result = []string{}
 	for _, authorId := range ids {
-		result.Result = append(result.Result.([]string), findByTag(response.Entities[authorId].Labels, language))
+		result.Result = append(result.Result.([]string), findByTag(response.Entities[authorId].Labels, language, ""))
 	}
 	return gott.Tuple(args), err
 }