godrudge

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 13 Imported by: 0

README

Table of Contents

DISCLAIMER:

This project is an independent, unofficial implementation and is not affiliated with or endorsed by Drudge. It is provided for educational and experimental purposes only.

Please note that this implementation relies on parsing the website’s HTML DOM, which, unlike a formal API, does not adhere to a fixed contract. As a result, any modifications to the website’s structure may cause the implementation to break. Users should be aware of these limitations when using this package.

image

Example Usage:

How to access the parsed headlines from the client

package main

import (
    "fmt"

    "github.com/mikegetz/godrudge"
)

func main() {
    client := godrudge.NewClient()
    err := client.ParseRSS()
    if err != nil {
        fmt.Println("Error parsing", err)
    }

    client.PrintDrudge(true)

    //Access the first headline title from Column 1
    fmt.Println(client.Page.HeadlineColumns[0][0].Title)
    fmt.Println(client.Page.HeadlineColumns[0][0].Href)

    //Access the first headline title from Column 2
    fmt.Println(client.Page.HeadlineColumns[1][0].Title)
    fmt.Println(client.Page.HeadlineColumns[1][0].Href)

    //Access the first headline title from Column 3
    fmt.Println(client.Page.HeadlineColumns[2][0].Title)
    fmt.Println(client.Page.HeadlineColumns[2][0].Href)
}
package main

import (
    "fmt"

    "github.com/mikegetz/godrudge"
)

func main() {
    client := godrudge.NewClient()
    err := client.ParseRSS()
    if err != nil {
        fmt.Println("Error parsing", err)
    }

    // set to true to print without ANSI links
    client.PrintDrudge(false)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	Page       Page
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c ...*http.Client) *Client

provide a client override

func (*Client) ParseDOM

func (c *Client) ParseDOM() error

Use HTML DOM parser

func (*Client) ParseRSS

func (c *Client) ParseRSS() error

func (*Client) PrintDrudge

func (c *Client) PrintDrudge(textOnly bool)

Print Drudge Prints drudge page to stdout

textOnly - prints to stdout without ansi links

type Headline

type Headline struct {
	Title string
	Href  string
	Color color.Color
}

type Page

type Page struct {
	Title           string
	TopHeadlines    []Headline
	MainHeadlines   []Headline
	HeadlineColumns [][]Headline
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳