pyrtan / sourcev0.19.0 · main

pyrtan / examples / hacker-news / hacker-news.toml

1,931 bytes · last changed 2026-10-26 in The catalog grows up: namespaces, publishing by pull request through the gate, gap reports gossiped back to authors; release 0.8.0

1# Hacker News, through its public Firebase API. Two trees: this one answers
2# the question, and `hacker-news-item` fetches one story, so that `each`
3# can reuse it.
4
5name = "hacker-news"
6version = 2
7namespace = "pyrtan"
8description = "Top stories on Hacker News, from its public API."
9tags = ["news", "read-only"]
10license = "MIT"
11hosts = ["hacker-news.firebaseio.com"]
12start = "fetch-ids"
13
14[[triggers]]
15pattern = "[what's the] top story on hacker news"
16inputs = { count = 1 }
17
18[[triggers]]
19pattern = "top {count:int} stories on hacker news"
20
21[inputs.count]
22type = "int"
23default = 1
24min = 1
25max = 30
26description = "How many stories to return"
27
28[nodes.fetch-ids]
29kind = "observe"
30http = { method = "GET", url = "https://hacker-news.firebaseio.com/v0/topstories.json" }
31into = "ids_resp"
32extract = [{ into = "ids", json = "json" }]
33next = "check"
34
35[nodes.check]
36kind = "decide"
37on = "ids_resp.status"
38branches = [
39 { when = { eq = 200 }, then = "any" },
40 { when = { gte = 500 }, then = "hn-down" },
41 { else = "unexpected" },
42]
43
44[nodes.any]
45kind = "decide"
46on = "ids"
47branches = [
48 { when = { empty = true }, then = "nothing" },
49 { when = { type = "list" }, then = "stories" },
50 { else = "unexpected" },
51]
52
53[nodes.stories]
54kind = "each"
55over = "ids"
56limit = "{{ inputs.count }}"
57tree = "hacker-news-item"
58with = { id = "{{ item }}" }
59into = "stories"
60next = "reply"
61
62[nodes.reply]
63kind = "done"
64say = "Top of Hacker News: {{ state.stories[0].title }} — {{ state.stories[0].url }}"
65output = { stories = "{{ state.stories }}" }
66
67[nodes.nothing]
68kind = "fail"
69reason = "no-stories"
70say = "Hacker News returned an empty front page."
71
72[nodes.hn-down]
73kind = "fail"
74reason = "upstream-down"
75say = "Hacker News answered {{ state.ids_resp.status }}; try again later."
76
77[nodes.unexpected]
78kind = "fail"
79reason = "unexpected-response"
80say = "Hacker News answered {{ state.ids_resp.status }} with something this tree does not recognise."