mirror of https://git.nuv.sh/nuv/condition_overload

swap to gleam_fetch, works on js now

nnuuvv 4fd65e3a cde361fb

+2
gleam.toml
··· 20 20 html_parser = ">= 1.0.1 and < 2.0.0" 21 21 splitter = ">= 1.0.0 and < 2.0.0" 22 22 argv = ">= 1.0.2 and < 2.0.0" 23 + gleam_fetch = ">= 1.3.0 and < 2.0.0" 24 + gleam_javascript = ">= 1.0.0 and < 2.0.0" 23 25 24 26 [dev-dependencies] 25 27 gleeunit = ">= 1.0.0 and < 2.0.0"
+4
manifest.toml
··· 3 3 4 4 packages = [ 5 5 { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 6 + { name = "gleam_fetch", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_javascript", "gleam_stdlib"], otp_app = "gleam_fetch", source = "hex", outer_checksum = "2CBF9F2E1C71AEBBFB13A9D5720CD8DB4263EB02FE60C5A7A1C6E17B0151C20C" }, 6 7 { name = "gleam_http", version = "4.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "DD0271B32C356FB684EC7E9F48B1E835D0480168848581F68983C0CC371405D4" }, 8 + { name = "gleam_javascript", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "EF6C77A506F026C6FB37941889477CD5E4234FCD4337FF0E9384E297CB8F97EB" }, 7 9 { name = "gleam_stdlib", version = "0.62.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "DC8872BC0B8550F6E22F0F698CFE7F1E4BDA7312FDEB40D6C3F44C5B706C8310" }, 8 10 { name = "gleeunit", version = "1.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "FDC68A8C492B1E9B429249062CD9BAC9B5538C6FBF584817205D0998C42E1DAC" }, 9 11 { name = "html_parser", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "html_parser", source = "hex", outer_checksum = "EEC0A3891CE99A49A8BB99086A06F56441D2ACF9436CE33ADBE51CE277D2D607" }, ··· 13 15 14 16 [requirements] 15 17 argv = { version = ">= 1.0.2 and < 2.0.0" } 18 + gleam_fetch = { version = ">= 1.3.0 and < 2.0.0" } 16 19 gleam_http = { version = ">= 4.1.1 and < 5.0.0" } 20 + gleam_javascript = { version = ">= 1.0.0 and < 2.0.0" } 17 21 gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } 18 22 gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 19 23 html_parser = { version = ">= 1.0.1 and < 2.0.0" }
+35 -30
src/condition_overload.gleam
··· 1 1 import argv 2 + import gleam/fetch 3 + import gleam/http/request 4 + import gleam/javascript/promise 2 5 import gleam/list 3 6 import gleam/pair 4 7 import gleam/result 5 8 import gleam/string 6 - import shellout 7 9 import splitter 8 10 9 11 pub fn main() { ··· 17 19 18 20 let _ = 19 21 [ 20 - "https://wiki.warframe.com/w/Condition_Overload_(Mechanic)?action=edit&section=7", 21 - "https://wiki.warframe.com/w/Condition_Overload_(Mechanic)?action=edit&section=8", 22 + "https://wiki.warframe.com/w/Condition_Overload_%28Mechanic%29?action=edit&section=7", 23 + "https://wiki.warframe.com/w/Condition_Overload_%28Mechanic%29?action=edit&section=8", 22 24 ] 23 - |> list.map(get_page_data) 24 - |> result.values() 25 - |> list.flatten() 26 - |> list.find(fn(item) { 27 - item.names 28 - |> list.any(fn(name) { 29 - let lower = string.lowercase(name) 30 - string.contains(lower, search) 31 - }) 32 - }) 33 - |> echo 34 - 35 - Nil 25 + |> list.map(do_request) 26 + |> promise.await_list() 27 + |> promise.map(result.values) 28 + |> promise.map(list.flatten) 29 + |> promise.map( 30 + list.find(_, fn(item) { 31 + item.names 32 + |> list.any(fn(name) { 33 + let lower = string.lowercase(name) 34 + string.contains(lower, search) 35 + }) 36 + }), 37 + ) 38 + |> promise.map(fn(x) { echo x }) 36 39 } 37 40 38 41 // do request and return Row if successful 39 42 // 40 - fn get_page_data(url: String) -> Result(List(Row), Nil) { 41 - { 42 - use shell_result <- result.try( 43 - shellout.command(run: "curl", with: [url, "--silent"], in: ".", opt: []), 44 - ) 43 + fn do_request( 44 + url: String, 45 + ) -> promise.Promise(Result(List(Row), fetch.FetchError)) { 46 + let assert Ok(req) = request.to(url) 45 47 46 - Ok( 47 - shell_result 48 - |> get_text_area() 49 - |> result.map(parse_text_area) 50 - |> result.unwrap([]), 51 - ) 52 - } 53 - |> result.replace_error(Nil) 48 + // Send the HTTP request to the server 49 + use resp <- promise.try_await(fetch.send(req)) 50 + use resp <- promise.try_await(fetch.read_text_body(resp)) 51 + 52 + let rows = 53 + resp.body 54 + |> get_text_area() 55 + |> result.map(parse_text_area) 56 + |> result.unwrap([]) 57 + 58 + promise.resolve(Ok(rows)) 54 59 } 55 60 56 61 // discards the html and returns only the raw text from the textarea ··· 75 80 |> process_lines([]) 76 81 } 77 82 78 - type Row { 83 + pub type Row { 79 84 Row( 80 85 names: List(String), 81 86 attack: String,