wiki

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: MIT Imports: 7 Imported by: 0

README

Build Status Godoc license Go Report Card

wiki

Command line tool to get Wikipedia summaries.

The tool can fetch summaries from any MediaWiki wiki with the API active, but defaults to the English Wikipedia.

Installation

To be able to install with go get requires you to have your $GOPATH setup and your $GOPATH/bin added to path as described here http://golang.org/doc/code.html#GOPATH.

If you don't want the man file you can just install it with go get.

$ go get github.com/walle/wiki/cmd/wiki

If you want to install the man file you can install with go get, but then use the make install command from the source directory.

$ go get github.com/walle/wiki
$ cd $GOPATH/src/github.com/walle/wiki
$ make install

or just copy the man file in _doc/wiki.1 to /usr/local/share/man/man1 or where you keep your man files.

Usage

To get a summary from Wikipedia in English just invoke the tool with a query.

$ wiki golang
Redirected from Golang to Go (programming language)

Go, also commonly referred to as golang, is a programming language developed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a statically typed language with syntax loosely derived from that of C, adding garbage collection, type safety, some structural typing capabilities, additional built-in types such as variable-length arrays & key-value maps, and a large standard library.
The language was announced in November 2009 and is now used in some of Google's production systems. Go's "gc" compiler targets the Linux, OS X, FreeBSD, NetBSD, OpenBSD, Plan 9, DragonFly BSD, Solaris, and Windows operating systems and the i386, Amd64, ARM and IBM POWER processor architectures. A second compiler, gccgo, is a GCC frontend.
Android support was added in version 1.4, which has since been ported to also run on iOS.

Read more: https://en.wikipedia.org/wiki/Go_(programming_language)

To get a localized result, e.g. in Swedish use the -l flag.

$ wiki -l sv ruby

or using System Environment:

$ WIKI_LANG="sv" wiki ruby

Use the -h flag to see all options (or man wiki if you have it installed)

$wiki -h
wiki is a tool used to fetch exerpts from wikipedia
Usage: wiki [options...] query
Options:

  -h    Print help information and exit.
  -l string
        The language to use (default "en")
  -n    If the output should not be colorized
  -no-check-certificate
        Skip verification of certificates
  -s    If simple output should be used
  -short
        If short output should be used
  -u string
        The api url (default "https://%s.wikipedia.org/w/api.php")
  -version
        Print version information and exit.
  -w int
        The width text should be wrapped at. 0 is no wrap.
Use another wiki

To get excerpts from another wiki use the -u flag to give another url to the API to use.

$ wiki -u https://en.wikiversity.org/w/api.php physics

This gives the excerpt from the wiki at wikiversity.org instead of Wikipedia.

Advice

If you frequently use the tool to fetch data from a custom url, add an alias. E.g. for bash. Add an alias to your .bash_profile or .bashrc file.

alias uwiki='wiki -u https://en.wikiversity.org/w/api.php '

And call it using

$ uwiki physics

or using System Environment in your .bash_profile or .bashrcfile.

echo "export WIKI_URL=https://en.wikiversity.org/w/api.php" >> .bashrc
# reload shell / source .bashrc
wiki physics

Testing

Run the tests using the make target test make test, this runs both the unit and the integration tests. For running only one type of tests use go test -cover and ./integration-tests.sh respectively.

$ make test

Contributing

All contributions are welcome! See CONTRIBUTING for more info.

License

The code is under the MIT license. See LICENSE for more information.

Documentation

Overview

Package wiki contains functionality to fetch extracts from a MediaWiki api.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Page

type Page struct {
	ID       int
	Title    string
	Content  string
	Language string
	URL      string
	Redirect *redirect
}

Page contains the parsed data.

type Request

type Request struct {
	*url.URL
}

Request sets up the request against the api with the correct parameters and has functionality to fetch the data and convert it to a response.

func NewRequest

func NewRequest(baseURL, query, language string) (*Request, error)

NewRequest creates a new request against baseURL for language. Language is interpolated in the baseURL if asked, if not it is ignored. Query is the title of the page to fetch. Returns an error if the URL can not be parsed.

func (*Request) Execute

func (r *Request) Execute(noCheckCert bool) (*Response, error)

Execute fetches the data and decodes it into a Response. Returns an error if the data could not be retrieved or the decoding fails.

type Response

type Response struct {
	Batchcomplete string
	Query         query
}

Response contains the raw data the API returns.

func (*Response) Page

func (r *Response) Page() (*Page, error)

Page parses the raw data and returns a Page with the relevant data.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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