aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hnscrape/hn.go18
-rw-r--r--cmd/hnscrape/main.go10
2 files changed, 27 insertions, 1 deletions
diff --git a/cmd/hnscrape/hn.go b/cmd/hnscrape/hn.go
index c580988..f05f989 100644
--- a/cmd/hnscrape/hn.go
+++ b/cmd/hnscrape/hn.go
@@ -219,6 +219,24 @@ func (h *HNClient) getItem(ctx context.Context, id int) (*HNItem, error) {
return &item, nil
}
+func (h *HNClient) PathToRoot(ctx context.Context, id int) ([]int, error) {
+ item, err := h.GetItem(ctx, id)
+ if err != nil {
+ return nil, err
+ }
+
+ if item.Parent == nil {
+ return []int{id}, nil
+ }
+
+ parents, err := h.PathToRoot(ctx, *item.Parent)
+ if err != nil {
+ return nil, err
+ }
+
+ return append(parents, id), nil
+}
+
func (h *HNClient) GetUltimateParent(ctx context.Context, id int) (*HNItem, error) {
item, err := h.GetItem(ctx, id)
if err != nil {
diff --git a/cmd/hnscrape/main.go b/cmd/hnscrape/main.go
index 5e3440a..78dc4f4 100644
--- a/cmd/hnscrape/main.go
+++ b/cmd/hnscrape/main.go
@@ -42,7 +42,7 @@ func main() {
os.Exit(1)
}
- slog.Info("got user", "user", u)
+ slog.Info("got user", "user", u.Created.String(), "karma", u.Karma, "submitted", len(u.Submitted))
// itemsCommentedIn := make([]int, 0)
//
@@ -142,6 +142,14 @@ func main() {
os.Exit(1)
}
*/
+
+ pathToRoot, err := hn.PathToRoot(ctx, 40699123)
+ if err != nil {
+ slog.Error("failed to get path to root", "err", err)
+ os.Exit(1)
+ }
+
+ slog.Info("got path to root", "pathToRoot", pathToRoot)
}
func ControlCContext() (context.Context, context.CancelFunc) {