wikigopher

package module
v0.0.0-...-81cbce0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2019 License: MIT Imports: 5 Imported by: 1

README

wikigopher

A wrapper around Wikipedia's API for Golang

Inspired by the Wikipedia wrapper for Python (https://github.com/goldsmith/Wikipedia)

Go Report Card


Start using wikipedia for Go in less than 5 minutes!

Begin by installing wikigopher:

$ go get github.com/Ishaangandhi/wikigopher

Features

First, import wikigopher:

import "github.com/ishaangandhi/wikigopher"
WikipediaPage Struct

WikipediaPage represents a Wikipedia Page

type WikipediaPage struct {
	PageID     uint64
	Title      string
	Content    string
	Categories []string
	Links      []string
}

To get a WikipediaPage just use the Page() function with a search query. For example:

page, err := wikigopher.Page("nyc")
fmt.Println(page.Title)
// prints "New York City"

fmt.Println(page.Content)
// prints "The City of New York, usually called either New York
// City (NYC) or simply New York (NY)"...

fmt.Println(page.Links)
// prints "[10 Hudson Yards 110th Street (Manhattan) 120th Street...]"

Search function

Search does a Wikipedia search of query and returns a slice of the result titles

func main() {
	var searchResults []string

	searchResults = wikigopher.Search("barack obama")
	fmt.Println(searchResults)
	// prints [Barack Obama Barack Obama Sr. Family of Barack Obama...]

	searchResults = wikigopher.Search("golang")
	fmt.Println(searchResults)
	// prints [Go (programming language) Data mapper pattern Template..]
}
Summary function

Summary returns the Wikipedia summary for a given search query

func main() {
	var summary string

	summary = wikigopher.Summary("barack obama")
	fmt.Println(summary)
	// prints: "Barack Hussein Obama II ( (listen); born August 4, 1961) is
	// an American attorney..."

	summary = wikigopher.Summary("golang")
	fmt.Println(summary)
	// prints: "Go (also referred to as Golang) is a statically typed,
	// compiled programming language..."
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Search(query string) []string

Search does a Wikipedia search of query and returns a slice of the result titles

func Summary

func Summary(query string) string

Summary returns the Wikipedia summary for a given search query

Types

type WikipediaPage

type WikipediaPage struct {
	PageID     uint64
	Title      string
	Content    string
	Categories []string
	Links      []string
}

WikipediaPage represents a Wikipedia Page

func Page

func Page(query string) (*WikipediaPage, error)

Page returns the WikipediaPage object for a given search query

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL