pyrtan / sourcev0.19.0 · main

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

1,694 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

1name = "hacker-news-item"
2version = 2
3namespace = "pyrtan"
4description = "One Hacker News item by id: title, url, score, author."
5tags = ["news", "read-only"]
6license = "MIT"
7hosts = ["hacker-news.firebaseio.com"]
8start = "fetch"
9
10[[triggers]]
11pattern = "hacker news item {id:int}"
12
13[inputs.id]
14type = "int"
15min = 1
16description = "The item id"
17
18[nodes.fetch]
19kind = "observe"
20http = { method = "GET", url = "https://hacker-news.firebaseio.com/v0/item/{{ inputs.id }}.json" }
21into = "resp"
22extract = [
23 { into = "title", json = "json.title" },
24 { into = "url", json = "json.url" },
25 { into = "score", json = "json.score" },
26 { into = "by", json = "json.by" },
27 { into = "type", json = "json.type" },
28]
29next = "kind"
30
31[nodes.kind]
32kind = "decide"
33on = "type"
34branches = [
35 { when = { eq = "story" }, then = "has-url" },
36 { when = { eq = "job" }, then = "has-url" },
37 { when = { exists = false }, then = "missing" },
38 { else = "not-a-story" },
39]
40
41[nodes.has-url]
42kind = "decide"
43on = "url"
44branches = [
45 { when = { exists = true }, then = "reply" },
46 { else = "self-post" },
47]
48
49[nodes.self-post]
50kind = "set"
51set = { url = "https://news.ycombinator.com/item?id={{ inputs.id }}" }
52next = "reply"
53
54[nodes.reply]
55kind = "done"
56say = "{{ state.title }} ({{ state.score }} points, by {{ state.by }}) {{ state.url }}"
57output = { id = "{{ inputs.id }}", title = "{{ state.title }}", url = "{{ state.url }}", score = "{{ state.score }}", by = "{{ state.by }}" }
58
59[nodes.missing]
60kind = "fail"
61reason = "no-such-item"
62say = "There is no Hacker News item {{ inputs.id }}."
63
64[nodes.not-a-story]
65kind = "fail"
66reason = "not-a-story"
67say = "Item {{ inputs.id }} is a {{ state.type }}, not a story."