gnews

package
v1.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// Topic
	TopicWorld         string = "WORLD"
	TopicNation        string = "NATION"
	TopicBusiness      string = "BUSINESS"
	TopicTechnology    string = "TECHNOLOGY"
	TopicEntertainment string = "ENTERTAINMENT"
	TopicSports        string = "SPORTS"
	TopicScience       string = "SCIENCE"
	TopicHealth        string = "HEALTH"
)
View Source
const (
	LanguageEnglish            = "en"
	LanguageIndonesian         = "id"
	LanguageCzech              = "cs"
	LanguageGerman             = "de"
	LanguageSpanish            = "es-419"
	LanguageFrench             = "fr"
	LanguageItalian            = "it"
	LanguageLatvian            = "lv"
	LanguageLithuanian         = "lt"
	LanguageHungarian          = "hu"
	LanguageDutch              = "nl"
	LanguageNorwegian          = "no"
	LanguagePolish             = "pl"
	LanguagePortugueseBrasil   = "pt-419"
	LanguagePortuguesePortugal = "pt-150"
	LanguageRomanian           = "ro"
	LanguageSlovak             = "sk"
	LanguageSlovenian          = "sl"
	LanguageSwedish            = "sv"
	LanguageVietnamese         = "vi"
	LanguageTurkish            = "tr"
	LanguageGreek              = "el"
	LanguageBulgarian          = "bg"
	LanguageRussian            = "ru"
	LanguageSerbian            = "sr"
	LanguageUkrainian          = "uk"
	LanguageHebrew             = "he"
	LanguageArabic             = "ar"
	LanguageMarathi            = "mr"
	LanguageHindi              = "hi"
	LanguageBengali            = "bn"
	LanguageTamil              = "ta"
	LanguageTelugu             = "te"
	LanguageMalyalam           = "ml"
	LanguageThai               = "th"
	LanguageChineseSimplified  = "zh-Hans"
	LanguageChineseTraditional = "zh-Hant"
	LanguageJapanese           = "ja"
	LanguageKorean             = "ko"
)

Host Language

View Source
const (
	LocationAustralia          = "AU"
	LocationBotswana           = "BW"
	LocationCanada             = "CA"
	LocationEthiopia           = "ET"
	LocationGhana              = "GH"
	LocationIndia              = "IN"
	LocationIndonesia          = "ID"
	LocationIreland            = "IE"
	LocationIsrael             = "IL"
	LocationKenya              = "KE"
	LocationLatvia             = "LV"
	LocationMalaysia           = "MY"
	LocationNamibia            = "NA"
	LocationNewZealand         = "NZ"
	LocationNigeria            = "NG"
	LocationPakistan           = "PK"
	LocationPhilippines        = "PH"
	LocationSingapore          = "SG"
	LocationSouthAfrica        = "ZA"
	LocationTanzania           = "TZ"
	LocationUganda             = "UG"
	LocationUnitedKingdom      = "GB"
	LocationUnitedStates       = "US"
	LocationZimbabwe           = "ZW"
	LocationCzechRepublic      = "CZ"
	LocationGermany            = "DE"
	LocationAustria            = "AT"
	LocationSwitzerland        = "CH"
	LocationArgentina          = "AR"
	LocationChile              = "CL"
	LocationColombia           = "CO"
	LocationCuba               = "CU"
	LocationMexico             = "MX"
	LocationPeru               = "PE"
	LocationVenezuela          = "VE"
	LocationBelgium            = "BE"
	LocationFrance             = "FR"
	LocationMorocco            = "MA"
	LocationSenegal            = "SN"
	LocationItaly              = "IT"
	LocationLithuania          = "LT"
	LocationHungary            = "HU"
	LocationNetherlands        = "NL"
	LocationNorway             = "NO"
	LocationPoland             = "PL"
	LocationBrazil             = "BR"
	LocationPortugal           = "PT"
	LocationRomania            = "RO"
	LocationSlovakia           = "SK"
	LocationSlovenia           = "SI"
	LocationSweden             = "SE"
	LocationVietnam            = "VN"
	LocationTurkey             = "TR"
	LocationGreece             = "GR"
	LocationBulgaria           = "BG"
	LocationRussia             = "RU"
	LocationUkraine            = "UA"
	LocationSerbia             = "RS"
	LocationUnitedArabEmirates = "AE"
	LocationSaudiArabia        = "SA"
	LocationLebanon            = "LB"
	LocationEgypt              = "EG"
	LocationBangladesh         = "BD"
	LocationThailand           = "TH"
	LocationChina              = "CN"
	LocationTaiwan             = "TW"
	LocationHongKong           = "HK"
	LocationJapan              = "JP"
	LocationRepublicOfKorea    = "KR"
)

Geographic Location

Variables

View Source
var (
	TopicMap = map[string]string{
		TopicWorld:         "w",
		TopicNation:        "n",
		TopicBusiness:      "b",
		TopicTechnology:    "t",
		TopicEntertainment: "e",
		TopicSports:        "s",
		TopicScience:       "snc",
		TopicHealth:        "m",
	}
)

Functions

This section is empty.

Types

type GNews

type GNews struct {
	// contains filtered or unexported fields
}

GNews is the main struct

func NewGNews

func NewGNews() *GNews

NewGNews creates a new GNews instance Language and location are optional If you don't specify them, the default language and location will be used The default language is traditional Chinese The default location is TW Language is the language of the news (e.g. en, fr, de, etc.) Location is the location of the news (e.g. US, FR, DE, etc.)

func (g *GNews) ConvertToOriginalLinks(items []*News)

ConvertToOriginalLinks converts the google news links to original links

func (*GNews) GetFilteredItems added in v1.1.0

func (g *GNews) GetFilteredItems(items []*News) []*News

getFilteredItems filters the items

func (*GNews) GetLocationNews

func (g *GNews) GetLocationNews(location string) ([]*News, error)

GetLocationNews gets the news by location

func (*GNews) GetTopNews

func (g *GNews) GetTopNews() ([]*News, error)

GetTop gets the top news

func (*GNews) GetTopicNews

func (g *GNews) GetTopicNews(topic string) ([]*News, error)

GetNewsByTopic gets the news by topic

func (*GNews) SearchNews

func (g *GNews) SearchNews(query string) ([]*News, error)

Search searches the news

func (*GNews) SetEndDate

func (g *GNews) SetEndDate(endDate *time.Time) *GNews

SetEndDate sets the end date of the news If you want to set a custom period, use SetPeriod

func (*GNews) SetExcludeWebsites

func (g *GNews) SetExcludeWebsites(excludeWebsites []string) *GNews

SetExcludeWebsites sets the websites to exclude from the results

func (*GNews) SetLanguage

func (g *GNews) SetLanguage(language string) *GNews

SetLanguage sets the language of the news

func (*GNews) SetLimit

func (g *GNews) SetLimit(limit int) *GNews

SetLimit sets the limit of the results

func (*GNews) SetLocation

func (g *GNews) SetLocation(location string) *GNews

SetLocation sets the location of the news

func (*GNews) SetPeriod

func (g *GNews) SetPeriod(period *time.Duration) *GNews

SetPeriod sets the period of the news Available periods are: 1h, 1d, 7d, 30d, 1y If you want to set a custom period, use SetStartDate and SetEndDate

func (*GNews) SetProxy

func (g *GNews) SetProxy(proxy string) *GNews

SetProxy sets the proxy to use

func (*GNews) SetStartDate

func (g *GNews) SetStartDate(startDate *time.Time) *GNews

SetStartDate sets the start date of the news If you want to set a custom period, use SetPeriod

type News

type News struct {
	Title           string
	Description     string
	Link            string
	Links           []string
	Content         string
	Published       string
	PublishedParsed *time.Time
	Updated         string
	UpdatedParsed   *time.Time
	GUID            string
	ImageURL        string
	Categories      []string
}
func (n *News) ConvertToOriginalLinks() error

func (*News) FetchContent

func (n *News) FetchContent() (string, error)

func (*News) FillContent added in v1.1.1

func (n *News) FillContent() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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