nx_eco_research_fetch.nx source
↩ module page · 101 lines · 8501 B
1// nx_eco_research_fetch.nx -- the Nishi RESEARCHER expanded into the REGENERATIVE LANDSCAPE (operator: "more than
2// edibles -- plants that are medicinal or great for wildlife in all our calculations; rainwater harvesting with
3// 3D-printed concrete structures; climbing useful plants like jasmine/grapes on the concrete; share with wildlife
4// while discouraging damage; optimal use of the environment while improving it"). Sources span medicinal plants,
5// pollinator/wildlife habitat, rainwater harvesting, 3D concrete printing + plant-support structures, and useful
6// climbing vines. Mirrors the proven fetch pattern (own TLS-1.3 + Mozilla CA, idempotent have-skip), saving to
7// knowledge/fetched/eco_*.raw. 100% sovereign. COVERAGE: 38 sources. expect_exit: 0 license_tier: ORIGINAL
8import "nx_syscalls.nx"
9import "nx_x509_trust_store.nx"
10import "nx_trust_store_load_from_certdata.nx"
11import "nx_https_fetch_follow.nx"
12const K_MAGIC_4194304: i64 = 4194304
13const K_MAGIC_8388608: i64 = 8388608
14
15func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
16func ff_putn(v: i64) -> i64 {
17 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
18 var m: i64 = v
19 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
20 let d: *u8 = sys_mmap(24); var k: i64 = 0
21 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
22 var j: i64 = k - 1
23 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
24 return 0
25}
26func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
27func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
28 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 }
29 let status: *i64 = sys_mmap(8) as *i64
30 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
31 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n)
32 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 }
33 var gz: i64 = 0
34 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
35 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 }
36 let fd: i64 = sys_openat_wr(opath, 0x1a4)
37 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 }
38 sys_write(fd, out, n)
39 sys_close(fd)
40 ff_puts(" SAVED\n" as *u8)
41 return 1
42}
43
44func main() -> i64 {
45 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
46 if r <= 0 { ff_puts("ECO: certdata load failed\n" as *u8); return 1 }
47 let store: *TrustStore = r as *TrustStore
48 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8)
49 let cap: i64 = K_MAGIC_8388608
50 let out: *u8 = sys_mmap(cap)
51 var ok: i64 = 0
52
53 ff_puts("== MEDICINAL PLANTS ==\n" as *u8)
54 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Medicinal_plants" as *u8, "knowledge/fetched/eco_m1_medicinal_plants.raw" as *u8, store, out, cap)
55 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Herbalism" as *u8, "knowledge/fetched/eco_m2_herbalism.raw" as *u8, store, out, cap)
56 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Echinacea" as *u8, "knowledge/fetched/eco_m3_echinacea.raw" as *u8, store, out, cap)
57 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Lavandula" as *u8, "knowledge/fetched/eco_m4_lavandula.raw" as *u8, store, out, cap)
58 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Achillea_millefolium" as *u8, "knowledge/fetched/eco_m5_yarrow.raw" as *u8, store, out, cap)
59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Calendula" as *u8, "knowledge/fetched/eco_m6_calendula.raw" as *u8, store, out, cap)
60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Comfrey" as *u8, "knowledge/fetched/eco_m7_comfrey.raw" as *u8, store, out, cap)
61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Sambucus" as *u8, "knowledge/fetched/eco_m8_elderberry.raw" as *u8, store, out, cap)
62
63 ff_puts("== WILDLIFE & POLLINATORS ==\n" as *u8)
64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Pollinator" as *u8, "knowledge/fetched/eco_w1_pollinator.raw" as *u8, store, out, cap)
65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Wildlife_garden" as *u8, "knowledge/fetched/eco_w2_wildlife_garden.raw" as *u8, store, out, cap)
66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Beneficial_insect" as *u8, "knowledge/fetched/eco_w3_beneficial_insect.raw" as *u8, store, out, cap)
67 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Butterfly_gardening" as *u8, "knowledge/fetched/eco_w4_butterfly_gardening.raw" as *u8, store, out, cap)
68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Asclepias" as *u8, "knowledge/fetched/eco_w5_milkweed.raw" as *u8, store, out, cap)
69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Insectary_plant" as *u8, "knowledge/fetched/eco_w6_insectary.raw" as *u8, store, out, cap)
70 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Hedgerow" as *u8, "knowledge/fetched/eco_w7_hedgerow.raw" as *u8, store, out, cap)
71
72 ff_puts("== RAINWATER HARVESTING ==\n" as *u8)
73 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Rainwater_harvesting" as *u8, "knowledge/fetched/eco_r1_rainwater_harvesting.raw" as *u8, store, out, cap)
74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Rain_garden" as *u8, "knowledge/fetched/eco_r2_rain_garden.raw" as *u8, store, out, cap)
75 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Greywater" as *u8, "knowledge/fetched/eco_r3_greywater.raw" as *u8, store, out, cap)
76 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Water_conservation" as *u8, "knowledge/fetched/eco_r4_water_conservation.raw" as *u8, store, out, cap)
77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Cistern" as *u8, "knowledge/fetched/eco_r5_cistern.raw" as *u8, store, out, cap)
78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Swale_(landform)" as *u8, "knowledge/fetched/eco_r6_swale.raw" as *u8, store, out, cap)
79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Drip_irrigation" as *u8, "knowledge/fetched/eco_r7_drip_irrigation.raw" as *u8, store, out, cap)
80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Xeriscaping" as *u8, "knowledge/fetched/eco_r8_xeriscaping.raw" as *u8, store, out, cap)
81
82 ff_puts("== 3D CONCRETE PRINTING & PLANT-SUPPORT STRUCTURES ==\n" as *u8)
83 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Construction_3D_printing" as *u8, "knowledge/fetched/eco_s1_construction_3dp.raw" as *u8, store, out, cap)
84 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Concrete" as *u8, "knowledge/fetched/eco_s2_concrete.raw" as *u8, store, out, cap)
85 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Trellis_(architecture)" as *u8, "knowledge/fetched/eco_s3_trellis.raw" as *u8, store, out, cap)
86 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Green_wall" as *u8, "knowledge/fetched/eco_s4_green_wall.raw" as *u8, store, out, cap)
87 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Espalier" as *u8, "knowledge/fetched/eco_s5_espalier.raw" as *u8, store, out, cap)
88 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Pergola" as *u8, "knowledge/fetched/eco_s6_pergola.raw" as *u8, store, out, cap)
89
90 ff_puts("== USEFUL CLIMBING VINES ==\n" as *u8)
91 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Vine" as *u8, "knowledge/fetched/eco_v1_vine.raw" as *u8, store, out, cap)
92 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Vitis" as *u8, "knowledge/fetched/eco_v2_grape.raw" as *u8, store, out, cap)
93 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Jasminum" as *u8, "knowledge/fetched/eco_v3_jasmine.raw" as *u8, store, out, cap)
94 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Passiflora" as *u8, "knowledge/fetched/eco_v4_passionflower.raw" as *u8, store, out, cap)
95 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Humulus_lupulus" as *u8, "knowledge/fetched/eco_v5_hops.raw" as *u8, store, out, cap)
96 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Wisteria" as *u8, "knowledge/fetched/eco_v6_wisteria.raw" as *u8, store, out, cap)
97 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Actinidia_deliciosa" as *u8, "knowledge/fetched/eco_v7_kiwi.raw" as *u8, store, out, cap)
98
99 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 38\n" as *u8)
100 return 0
101}