opinions

package module
v1.0.0 Latest Latest
Warning

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

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

README

opinions

Quality check status

Find opinions about given phrase (also URL) on social news websites: Hacker News and Lobsters. It can be used for including discussions on static websites/blogs.

opinions is command-line replacement of discu.eu service. It directly calls search engines on underlying websites.

Application is developed with security-first approach:

  • functionality is limited by design
  • access to the OS is restricted by application-level sandboxing (currently OpenBSD only).

Usage

$ opinions 'https://grugbrain.dev'
Lobsters	https://lobste.rs/s/ifaar4/grug_brained_developer	The Grug Brained Developer	https://grugbrain.dev/
Lobsters	https://lobste.rs/s/pmpc9v/grug_brained_developer	The Grug Brained Developer	http://grugbrain.dev
Hacker News	https://news.ycombinator.com/item?id=31840331	The Grug Brained Developer	https://grugbrain.dev/

The result is printed to stdout as rows in format: <service_name><tab><URL><tab><title><tab><source_domain>.

Websites are queried with User-Agent: opinions/<version_number> (<os>; +https://github.com/macie/opinions).

Development

Use make (GNU or BSD):

  • make - install dependencies
  • make test - runs test
  • make check - static code analysis
  • make build - compile binaries from latest commit for supported OSes (with proper version number)
  • make release - mark latest commit with choosen version tag and compile binaries for supported OSes
  • make clean - removes compilation artifacts
  • make info - print system info (useful for debugging).

Bugs

Results depends on search engines of underlying social news websites. They may be different than expected.

TODO

Add sandboxing for other OSes:

License

MIT

Documentation

Overview

Package opinions helps finding links to discussions about given topics/URLs on social news websites.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discussion

type Discussion struct {
	Service  string
	URL      string
	Title    string
	Source   string
	Comments int
}

Discussion is a representation of discussion inside social media service.

func SearchHackerNews

func SearchHackerNews(ctx context.Context, client http.Client, query string) ([]Discussion, error)

SearchHackerNews query HN Search API for given prompt. It returns list of stories which contains comments sorted by relevance, then popularity, then number of comments.

See: https://hn.algolia.com/api

Example
client := http.Client{}
query := "grugbrain.dev"

opinions := ensure.MustReturn(SearchHackerNews(context.TODO(), client, query))

fmt.Println(opinions[0])
Output:
Hacker News	https://news.ycombinator.com/item?id=31840331	The Grug Brained Developer	https://grugbrain.dev/

func SearchLobsters

func SearchLobsters(ctx context.Context, client http.Client, query string) ([]Discussion, error)

SearchLobsters query lobster search engine for given prompt. It returns list of stories which contains comments sorted by relevance.

Example
client := http.Client{}
query := "https://grugbrain.dev"

opinions := ensure.MustReturn(SearchLobsters(context.TODO(), client, query))

fmt.Println(opinions[0])
Output:
Lobsters	https://lobste.rs/s/ifaar4/grug_brained_developer	The Grug Brained Developer	https://grugbrain.dev/

func (Discussion) String

func (d Discussion) String() string

String returns string representation of discussion metadata.

type HackerNewsResponse

type HackerNewsResponse struct {
	Hits []struct {
		CreatedAt   time.Time `json:"created_at"`
		Title       string    `json:"title"`
		URL         string    `json:"url"`
		NumComments int       `json:"num_comments"`
		ObjectID    string    `json:"objectID"`
	} `json:"hits"`
}

HackerNewsResponse represents some interesting fields of response from HN Search API.

See: https://hn.algolia.com/api

Directories

Path Synopsis
Package ensure contains helpers for testable examples.
Package ensure contains helpers for testable examples.
Package http implements cancellable REST requests with custom User-Agent.
Package http implements cancellable REST requests with custom User-Agent.

Jump to

Keyboard shortcuts

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