code wiki / (root) / nx_foodsci_research_fetch.nx

nx_foodsci_research_fetch.nx source

↩ module page · 85 lines · 5532 B

1// nx_foodsci_research_fetch.nx -- the Nishi RESEARCHER's sovereign web-fetch 2// grounding the NEW food-science-suite rungs (preservation / nutrition / 3// cooking chemistry / HACCP / allergen / sensory) in real sources -- 4// "research not bro science" (Rule 4). Mirrors the proven 5// nx_probiome_research_fetch pattern: own TLS-1.3 + Mozilla CA, idempotent 6// have-skip, resume-on-kill, ->knowledge/fetched/foodsci_*.raw. 7// COVERAGE: 16 authoritative 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) 21 var k: i64 = 0 22 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 23 var j: i64 = k - 1 24 while j >= 0 { sys_write(1, (d as i64 + j) as *u8, 1); j = j - 1 } 25 return 0 26} 27func have_file(path: *u8) -> i64 { 28 let fd: i64 = sys_openat_rd(path) 29 if fd < 0 { return 0 } 30 sys_close(fd) 31 return 1 32} 33func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 34 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 } 35 let status: *i64 = sys_mmap(8) as *i64 36 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 37 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n) 38 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 } 39 var gz: i64 = 0 40 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 41 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 } 42 let fd: i64 = sys_openat_wr(opath, 0x1a4) 43 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 } 44 sys_write(fd, out, n) 45 sys_close(fd) 46 ff_puts(" SAVED\n" as *u8) 47 return 1 48} 49 50func main() -> i64 { 51 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 52 if r <= 0 { ff_puts("FOODSCI: certdata load failed\n" as *u8); return 1 } 53 let store: *TrustStore = r as *TrustStore 54 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8) 55 let cap: i64 = K_MAGIC_8388608 56 let out: *u8 = sys_mmap(cap) 57 var ok: i64 = 0 58 59 ff_puts("== PRESERVATION (thermal death, water activity, hurdle) ==\n" as *u8) 60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Food_preservation" as *u8, "knowledge/fetched/foodsci_p1_food_preservation.raw" as *u8, store, out, cap) 61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Canning" as *u8, "knowledge/fetched/foodsci_p2_canning.raw" as *u8, store, out, cap) 62 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Water_activity" as *u8, "knowledge/fetched/foodsci_p3_water_activity.raw" as *u8, store, out, cap) 63 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Hurdle_technology" as *u8, "knowledge/fetched/foodsci_p4_hurdle_technology.raw" as *u8, store, out, cap) 64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Pasteurization" as *u8, "knowledge/fetched/foodsci_p5_pasteurization.raw" as *u8, store, out, cap) 65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Botulism" as *u8, "knowledge/fetched/foodsci_p6_botulism.raw" as *u8, store, out, cap) 66 67 ff_puts("== NUTRITION (Atwater energy, daily values) ==\n" as *u8) 68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Food_energy" as *u8, "knowledge/fetched/foodsci_n1_food_energy.raw" as *u8, store, out, cap) 69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Reference_Daily_Intake" as *u8, "knowledge/fetched/foodsci_n2_reference_daily_intake.raw" as *u8, store, out, cap) 70 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Dietary_Reference_Intake" as *u8, "knowledge/fetched/foodsci_n3_dietary_reference_intake.raw" as *u8, store, out, cap) 71 72 ff_puts("== COOKING CHEMISTRY (browning reactions) ==\n" as *u8) 73 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Maillard_reaction" as *u8, "knowledge/fetched/foodsci_c1_maillard.raw" as *u8, store, out, cap) 74 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Caramelization" as *u8, "knowledge/fetched/foodsci_c2_caramelization.raw" as *u8, store, out, cap) 75 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Enzymatic_browning" as *u8, "knowledge/fetched/foodsci_c3_enzymatic_browning.raw" as *u8, store, out, cap) 76 77 ff_puts("== SAFETY / HACCP / ALLERGEN / SENSORY ==\n" as *u8) 78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Hazard_analysis_and_critical_control_points" as *u8, "knowledge/fetched/foodsci_h1_haccp.raw" as *u8, store, out, cap) 79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Food_safety" as *u8, "knowledge/fetched/foodsci_h2_food_safety.raw" as *u8, store, out, cap) 80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Food_allergy" as *u8, "knowledge/fetched/foodsci_a1_food_allergy.raw" as *u8, store, out, cap) 81 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Sensory_analysis" as *u8, "knowledge/fetched/foodsci_s1_sensory_analysis.raw" as *u8, store, out, cap) 82 83 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 16\n" as *u8) 84 return 0 85}