From 10428cd1826cd2deedb5754245c4f99e0390bb01 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 28 Oct 2025 03:37:30 -0400 Subject: [PATCH] path and data --- .../src/requests/index_page/get_numbers.rs | 70 +++---------------- .../verification_token_to_loading_anim.rs | 28 ++++++-- 2 files changed, 32 insertions(+), 66 deletions(-) diff --git a/crates/api_clients/grok_client/src/requests/index_page/get_numbers.rs b/crates/api_clients/grok_client/src/requests/index_page/get_numbers.rs index 9c33e3669e..6c7529aa16 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/get_numbers.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/get_numbers.rs @@ -1,10 +1,11 @@ +use crate::error::grok_client_error::GrokClientError; use crate::error::grok_error::GrokError; use crate::requests::index_page::requests::get_index_page_script_with_client::{get_index_page_script_with_client, GetIndexPageScriptArgs}; use crate::requests::index_page::utils::parse_numbers_from_xsid_script::parse_numbers_from_xsid_script; use crate::requests::index_page::utils::parse_on_demand_script_from_index_html::parse_on_demand_script_from_index_html; +use crate::requests::index_page::utils::parse_svg_paths_from_index_html::parse_svg_paths_from_index_html; use crate::requests::index_page::utils::verification_token_to_loading_anim::LoadingAnim; use wreq::Client; -use crate::requests::index_page::utils::parse_svg_paths_from_index_html::parse_svg_paths_from_index_html; // self.svg_data, self.numbers = Parser.parse_values(c_request.text, self.anim, self.xsid_script) @@ -19,6 +20,9 @@ pub struct GetNumbersArgs<'a> { #[derive(Clone, Debug)] pub struct NumbersAndSvg { pub numbers: Vec, + + /// We selected one of four possible SVG paths (of length >= 200) by the animation index. + pub svg_data: String, } pub async fn get_numbers(args: GetNumbersArgs<'_>) -> Result { @@ -33,65 +37,26 @@ pub async fn get_numbers(args: GetNumbersArgs<'_>) -> Result format!("https://grok.com/_next/{}", args.xsid_script_id), }; - println!("Script link: `{}`", script_link); - let xsid_script_body = get_index_page_script_with_client(GetIndexPageScriptArgs { client: &args.client, cookie: args.cookie, script_url: &script_link, }).await?; - println!("Xsid Script Body:\n\n"); - println!("{}", xsid_script_body); - println!("\n\n"); - let numbers = parse_numbers_from_xsid_script(&xsid_script_body); - println!("Numbers:\n\n"); - println!("{:?}", numbers); - println!("\n\n"); - let paths = parse_svg_paths_from_index_html(&args.html); - println!("Paths:\n\n"); - println!("{:?}", paths); - println!("\n\n"); - - /* - @staticmethod - def parse_values(html: str, loading: str = "loading-x-anim-0", scriptId: str = "") -> tuple[str, Optional[str]]: - - Parser._load__xsid_mapping() - - all_d_values = findall(r'"d":"(M[^"]{200,})"', html) - svg_data = all_d_values[int(loading.split("loading-x-anim-")[1])] - - if scriptId: - - if scriptId == "ondemand.s": - script_link: str = 'https://abs.twimg.com/responsive-web/client-web/ondemand.s.' + Utils.between(html, f'"{scriptId}":"', '"') + 'a.js' - else: - script_link: str = f'https://grok.com/_next/{scriptId}' - - if script_link in Parser.mapping: - numbers: list = Parser.mapping[script_link] - - else: - script_content: str = requests.get(script_link, impersonate="chrome136").text - numbers: list = [int(x) for x in findall(r'x\[(\d+)\]\s*,\s*16', script_content)] - Parser.mapping[script_link] = numbers - with open('core/mapping.json', 'w') as f: - dump(Parser.mapping, f) - - return svg_data, numbers - - else: - return svg_data - */ + let svg_data = paths.get(args.loading_anim.0); + let svg_data = match svg_data { + Some(s) => s.to_string(), + None => return Err(GrokClientError::ScriptLogicOutOfDate.into()), + }; Ok(NumbersAndSvg { numbers, + svg_data, }) } @@ -137,19 +102,6 @@ mod tests { println!("Final Numbers: {:?}", result); - println!("{:?}", result); - - println!("Body:\n\n"); - println!("{}", page_and_scripts.body); - println!("\n\n"); - - /* - ActionsAndXsid { - actions: ["7f09b4b48933c332d0ed2689be265eb736e75c76d9", "7fa957f192ada06e391443f7bcee666006d78d916f", "7f605b51836e8b9088638bb9991ed75227bdedefd2"], - xsid_script_path: "static/chunks/0db7b1a346e93e5b.js" - } - */ - assert_eq!(1, 2); Ok(()) } diff --git a/crates/api_clients/grok_client/src/requests/index_page/utils/verification_token_to_loading_anim.rs b/crates/api_clients/grok_client/src/requests/index_page/utils/verification_token_to_loading_anim.rs index e47faa4f8b..d75528fbf3 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/utils/verification_token_to_loading_anim.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/utils/verification_token_to_loading_anim.rs @@ -4,7 +4,13 @@ use base64::Engine; use log::error; #[derive(Debug, Clone)] -pub struct LoadingAnim(pub(crate) String); +pub struct LoadingAnim(pub(crate) usize); + +impl LoadingAnim { + pub fn to_id(&self) -> String { + format!("loading-x-anim-{}", self.0) + } +} /// The verification token comes from the index HTML. pub fn verification_token_to_loading_anim(verification_token: &str) -> Result { @@ -21,19 +27,27 @@ pub fn verification_token_to_loading_anim(verification_token: &str) -> Result AnyhowResult<()> { + assert_eq!(&to_id("aezWdJW6+WJhvtMA1faxopO11Q1JRcM6j7JcW/R0gO09CQhO7GzIs760yo1A0MnF")?, "loading-x-anim-2"); + assert_eq!(&to_id("wROL4+VivbPuVc37N+4VNq0K3cEMW0bPKuToO6JWxJ9fzsP3Rsn2eC8DDDZFFlov")?, "loading-x-anim-2"); + assert_eq!(&to_id("ckWUvquxT8AdPRpdjXTeNkkXRfKiGGnQFH3Hq4aznsUrSsjtDSI4JcO59j7U/+VQ")?, "loading-x-anim-1"); + Ok(()) + } + + fn to_id(verification_token: &str) -> Result { + let anim = verification_token_to_loading_anim(verification_token)?; + Ok(anim.to_id()) } }