gogooglenews

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 9 Imported by: 0

README

Inspired by pygooglenews

About

A golang based wrapper of the Google News RSS feed.

Top stories, topic related news feeds, geolocation news feed, and an extensive full text search feed.

This work is more of a collection of all things I could find out about how Google News functions.

Installation

go get github.com/spl0i7/gogooglenews

Quickstart


googleNews, err := NewGoogleNews(GoogleNewsOpt{
    Lang:    "en",
    Country: "IN",
})

Top Stories

news, err = googleNews.TopNews()

Stories by Topic

news, err = googleNews.TopicHeadlines("BUSINESS")

Geolocation Specific Stories

news, err = googleNews.GeoHeadlines("bangalore")


to := time.Now()
from := to.AddDate(0, 0, -10)

news, err = googleNews.Search("Bitcoin", &from, &to)

Proxy

If you make frequent calls to the rss service, its very much possible that Google might blacklist your IP.

To bypass this, ideally you should be making requests behind a proxy. To use a proxy pass the http client in options as following.

proxyUrl, err := url.Parse("http://proxyIp:proxyPort")
myClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}

googleNews, err := NewGoogleNews(GoogleNewsOpt{
    Lang:    "en",
    Country: "IN",
    HttpClient: myClient
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoogleNews

type GoogleNews interface {
	TopNews() ([]News, error)
	TopicHeadlines(topic string) ([]News, error)
	GeoHeadlines(geo string) ([]News, error)
	Search(query string, from, to *time.Time) ([]News, error)
}

func NewGoogleNews

func NewGoogleNews(opt GoogleNewsOpt) (GoogleNews, error)

type GoogleNewsOpt

type GoogleNewsOpt struct {
	Lang       string
	Country    string
	HttpClient *http.Client
}

type News

type News struct {
	Title       string
	Link        string
	Time        time.Time
	Description string
	Source      string
	SourceUrl   string
}

Jump to

Keyboard shortcuts

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