If you have go installed can just go get github.com/m1/hacker-news-cli
and run hacker-news-cli
OR
Can clone and build it yourself, e.g. GO111MODULE=on go build
Can run make
and will use docker to build.
Three basic commands:
hacker-news-cli
Gets the latest 30 posts from hacker news, can add --posts <int>
to determine how many posts are returned (max of 100), can also add --indent
to pretty
print the json or use something like jq. Example:
$ hacker-news-cli --posts 30 --indent
Returns (truncated)
[
{
"id": 18636113,
"rank": 1,
"author": "sbenitez",
"comments": 20,
"points": 104,
"title": "Rocket v0.4: Typed URIs, Database Support, Revamped Queries, and More",
"posted": 1544291822,
"uri": "https://rocket.rs/v0.4/news/2018-12-08-version-0.4/"
},
...
]
To save a post the command is just save <id>
(this uses a sqlite db). Example:
$ hacker-news-cli save 18636113
To view the saved posts, use the saved
command. As with getting the posts, you can
also use the --indent
flag here. Example:
$ hacker-news-cli saved --indent
Returns
[
{
"id": 18636113,
"author": "sbenitez",
"title": "Rocket v0.4: Typed URIs, Database Support, Revamped Queries, and More",
"posted": 1544288444,
"saved": 1544295644,
"uri": "https://rocket.rs/v0.4/news/2018-12-08-version-0.4/"
}
]
Can also use this as a library, example usage:
package main
import (
"github.com/m1/hacker-news-cli/pkg/hn"
"github.com/m1/hacker-news-cli/pkg/hn/config"
)
func main() {
client := hn.NewClient(&config.Config{
MaxPosts: 100,
})
posts := client.GetPosts(10)
for _, p := range posts {
println(p.Id)
}
post, _ := client.GetPost(18636113)
println(post.Id)
}