Improved Wikipedia IA to be lang specific
Some checks failed
Run Integration Tests / test (push) Failing after 40s
Some checks failed
Run Integration Tests / test (push) Failing after 40s
This commit is contained in:
parent
89264b0f87
commit
41f7eb4357
2 changed files with 10 additions and 21 deletions
13
ia-wiki.go
13
ia-wiki.go
|
@ -21,17 +21,18 @@ type WikipediaResponse struct {
|
|||
}
|
||||
|
||||
// Get Wikipedia summary
|
||||
func getWikipediaSummary(query string) (title, text, link string, ok bool) {
|
||||
// Clean and prepare query
|
||||
func getWikipediaSummary(query, lang string) (title, text, link string, ok bool) {
|
||||
// Clean inputs
|
||||
query = strings.TrimSpace(query)
|
||||
if query == "" {
|
||||
lang = strings.ToLower(strings.TrimSpace(lang))
|
||||
if query == "" || lang == "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
|
||||
// API request
|
||||
// Construct Wikipedia API URL with lang
|
||||
apiURL := fmt.Sprintf(
|
||||
"https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro&explaintext&redirects=1&titles=%s",
|
||||
url.QueryEscape(query),
|
||||
"https://%s.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro&explaintext&redirects=1&titles=%s",
|
||||
lang, url.QueryEscape(query),
|
||||
)
|
||||
|
||||
resp, err := http.Get(apiURL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue