package module
Version: v0.0.0-...-4829429 Latest Latest

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 18 Imported by: 1



Module for querying wolfram alpha, google, and youtube. Works great with the ultimateq irc bot.



Package query provides functions to query web interfaces.



This section is empty.


This section is empty.


func Bing

func Bing(query string, conf *Config) (output string, err error)

Bing performs a query and returns a formatted result.

func GetShortURL

func GetShortURL(longURL string, conf *Config) (short string, err error)

GetShortURL takes a long url and returns a shorter url from the Google API

func GithubStars

func GithubStars(userOrRepo string, conf *Config) (count int, err error)

GithubStars takes a user (aarondl) or repo (aarondl/query) and returns the number of stars.

func Google

func Google(query string, conf *Config) (output string, err error)

Google performs a query and returns a formatted result.

func WeatherYR

func WeatherYR(query string, conf *Config) (output string, err error)

WeatherYR provides weather information from yr.no

func Wolfram

func Wolfram(query string, conf *Config) (output string, err error)

Wolfram performs a query and returns a formatted result.

func YouTube

func YouTube(msg string, cfg *Config) (output string, err error)

YouTube will check to see if a message contains a YouTube uri, if so it will format a string with the title in it.


type BingAnswer

type BingAnswer struct {
	Type         string `json:"_type"`
	QueryContext struct {
		OriginalQuery string `json:"originalQuery"`
	} `json:"queryContext"`
	WebPages struct {
		WebSearchURL          string `json:"webSearchUrl"`
		TotalEstimatedMatches int    `json:"totalEstimatedMatches"`
		Value                 []struct {
			ID               string    `json:"id"`
			Name             string    `json:"name"`
			URL              string    `json:"url"`
			IsFamilyFriendly bool      `json:"isFamilyFriendly"`
			DisplayURL       string    `json:"displayUrl"`
			Snippet          string    `json:"snippet"`
			DateLastCrawled  time.Time `json:"dateLastCrawled"`
			SearchTags       []struct {
				Name    string `json:"name"`
				Content string `json:"content"`
			} `json:"searchTags,omitempty"`
			About []struct {
				Name string `json:"name"`
			} `json:"about,omitempty"`
		} `json:"value"`
	} `json:"webPages"`
	Videos struct {
		WebSearchURL          string `json:"webSearchUrl"`
		TotalEstimatedMatches int    `json:"totalEstimatedMatches"`
		Value                 []struct {
			ID          string `json:"id"`
			Name        string `json:"name"`
			Description string `json:"description"`
			ContentURL  string `json:"contentUrl"`
			HostPageURL string `json:"hostPageUrl"`
			Duration    string `json:"duration"`
		} `json:"value"`
	} `json:"videos"`
	RelatedSearches struct {
		ID    string `json:"id"`
		Value []struct {
			Text         string `json:"text"`
			DisplayText  string `json:"displayText"`
			WebSearchURL string `json:"webSearchUrl"`
		} `json:"value"`
	} `json:"relatedSearches"`
	RankingResponse struct {
		Mainline struct {
			Items []struct {
				AnswerType  string `json:"answerType"`
				ResultIndex int    `json:"resultIndex"`
				Value       struct {
					ID string `json:"id"`
				} `json:"value"`
			} `json:"items"`
		} `json:"mainline"`
		Sidebar struct {
			Items []struct {
				AnswerType string `json:"answerType"`
				Value      struct {
					ID string `json:"id"`
				} `json:"value"`
			} `json:"items"`
		} `json:"sidebar"`
	} `json:"rankingResponse"`

This struct formats the answers provided by the Bing Web Search API.

type BingError

type BingError struct {
	Type   string `json:"_type"`
	Errors []struct {
		Code      string `json:"code"`
		SubCode   string `json:"subCode"`
		Message   string `json:"message"`
		Parameter string `json:"parameter"`
	} `json:"errors"`

type Config

type Config struct {
	BingAPIKey         string `toml:"bing_api_key"`
	GeonamesID         string `toml:"geonames_id"`
	GithubAPIKey       string `toml:"github_api_key"`
	GoogleURLAPIKey    string `toml:"google_url_api_key"`
	GoogleSearchAPIKey string `toml:"google_search_api_key"`
	GoogleSearchCXID   string `toml:"google_search_cx_id"`
	GoogleYoutubeKey   string `toml:"google_youtube_key"`
	WolframID          string `toml:"wolfram_id"`

Config is the configuration for this thing.

func NewConfig

func NewConfig(file string) *Config

NewConfig loads the config file.

type GoogleQueries

type GoogleQueries struct {
	NextPage []GoogleQuery `json:"nextPage"`
	Request  []GoogleQuery `json:"request"`

GoogleQueries a set of queries involved in the current search query

type GoogleQuery

type GoogleQuery struct {
	CX             string `json:"cx"`
	Title          string `json:"title"`
	TotalResults   string `json:"totalResults"`
	SearchTerms    string `json:"searchTerms"`
	Count          int    `json:"count"`
	StartIndex     int    `json:"startIndex"`
	InputEncoding  string `json:"inputEncoding"`
	OutputEncoding string `json:"outputEncoding"`
	Safe           string `json:"safe"`

GoogleQuery is a description of a search query

type GoogleSearch

type GoogleSearch struct {
	Items   []GoogleSearchItem      `json:"items"`
	Info    GoogleSearchInformation `json:"searchInformation"`
	Queries GoogleQueries           `json:"queries"`

GoogleSearch is used to parse the response from Google.

type GoogleSearchInformation

type GoogleSearchInformation struct {
	TotalResults          string  `json:"totalResults"`
	SearchTime            float64 `json:"searchTime"`
	FormattedTotalResults string  `json:"formattedTotalResults"`
	FormattedSearchTime   string  `json:"formattedSearchTime"`

GoogleSearchInformation is meta about the search

type GoogleSearchItem

type GoogleSearchItem struct {
	Title        string `json:"title"`
	Snippet      string `json:"snippet"`
	Link         string `json:"link"`
	DisplayLink  string `json:"displayLink"`
	FormattedURL string `json:"formattedUrl"`

	HTMLTitle        string `json:"htmlTitle"`
	HTMLSnippet      string `json:"htmlSnippet"`
	HTMLFormattedURL string `json:"htmlFormattedUrl"`

	CacheID string `json:"cacheId"`
	Kind    string `json:"kind"`

GoogleSearchItem is a search result item from a google search

type Pod

type Pod struct {
	Title      string   `xml:"title,attr"`
	ID         string   `xml:"id,attr"`
	Primary    bool     `xml:"primary,attr"`
	Numsubpods int      `xml:"numsubpods,attr"`
	PlainTexts []string `xml:"subpod>plaintext"`

Pod is a substruct of WolframData.

type URLShortenQuery

type URLShortenQuery struct {
	LongURL string `json:"longUrl"`

URLShortenQuery is the json request to the server

type URLShortenResponse

type URLShortenResponse struct {
	ID      string `json:"id"`
	LongURL string `json:"longUrl"`

URLShortenResponse is the json response back from the server

type WolframData

type WolframData struct {
	XMLName     xml.Name `xml:"queryresult"`
	Success     bool     `xml:"success,attr"`
	ParseTiming float64  `xml:"parsetiming,attr"`
	Numpods     int      `xml:"numpods,attr"`
	Pods        []*Pod   `xml:"pod"`
	DidYouMeans []string `xml:"didyoumeans>didyoumean"`

WolframData is used to parse the response from WolframAlpha.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL