qwen3.5-9b testing
This commit is contained in:
parent
03cd6b9af0
commit
1f25b001e6
|
|
@ -7,7 +7,7 @@ This repository contains a synchronous Rust utility that fetches product data fr
|
|||
2. **Build/Run Order:** The intended command sequence is: `cargo build --release` followed by running the binary (`./target/release/antares_get_data`).
|
||||
3. **Development Flow:** Use this order when developing or verifying changes:
|
||||
* `cargo fmt --all -- --check` (Linting)
|
||||
- `cargo check` (Compile/Verify)
|
||||
* `cargo check` (Compile/Verify) - run after any file modifications
|
||||
* `cargo test` (Testing)
|
||||
|
||||
## 💻 Architecture & Quirks
|
||||
|
|
|
|||
53
src/main.rs
53
src/main.rs
|
|
@ -11,11 +11,29 @@ use api::make_url;
|
|||
use template::antares::Antares;
|
||||
use tools::{Logger, export_to_excel};
|
||||
|
||||
fn make_request(url: &str) -> Result<String, Box<dyn Error>> {
|
||||
fn make_request(url: &str, logger: &Logger) -> Result<String, Box<dyn Error>> {
|
||||
let client = Client::builder()
|
||||
.timeout(Duration::from_secs(300))
|
||||
.build()?;
|
||||
Ok(client.get(url).send()?.text()?)
|
||||
.build().map_err(|e| {
|
||||
logger.log_error(&format!("Failed to create HTTP client: {}", e));
|
||||
Box::new(std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
||||
})?;
|
||||
|
||||
let response = client.get(url).send().map_err(|e| {
|
||||
logger.log_error(&format!("HTTP request failed: {}", e));
|
||||
Box::new(std::io::Error::new(std::io::ErrorKind::ConnectionRefused, e.to_string()))
|
||||
})?;
|
||||
|
||||
if response.status().is_success() {
|
||||
Ok(response.text().map_err(|e| {
|
||||
logger.log_error(&format!("Failed to read response body: {}", e));
|
||||
Box::new(std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
||||
})?)
|
||||
} else {
|
||||
let error_msg = format!("HTTP error: {:?}", response.status());
|
||||
logger.log_error(&error_msg);
|
||||
Err(Box::new(std::io::Error::new(std::io::ErrorKind::ConnectionRefused, error_msg)))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
|
@ -37,13 +55,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
let url = make_url(base, &usercode, &password, cikkszam);
|
||||
|
||||
let response = match make_request(&url) {
|
||||
let response = match make_request(&url, &logger) {
|
||||
Ok(resp) => {
|
||||
logger.log_info("API request sent successfully");
|
||||
resp
|
||||
}
|
||||
Err(e) => {
|
||||
logger.log_api_failure(&e.to_string());
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
|
@ -52,16 +69,34 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let items: Antares = match serde_json::from_str::<Antares>(&response) {
|
||||
Ok(items) => {
|
||||
// Re-serialize via the structs to ensure consistent formatting
|
||||
let pretty = serde_json::to_string_pretty(&items)?;
|
||||
fs::write("antares.json", pretty)?;
|
||||
let pretty = match serde_json::to_string_pretty(&items) {
|
||||
Ok(pretty) => pretty,
|
||||
Err(e) => {
|
||||
logger.log_error(&format!("Failed to serialize items: {}", e));
|
||||
return Err(Box::new(e));
|
||||
}
|
||||
};
|
||||
fs::write("antares.json", &pretty).map_err(|e| {
|
||||
logger.log_error(&format!("Failed to write antares.json: {}", e));
|
||||
Box::new(std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
||||
})?;
|
||||
logger.log_api_success(items.len());
|
||||
items
|
||||
}
|
||||
Err(_) => {
|
||||
// Fall back to pretty-printing raw JSON value, or raw text.
|
||||
if let Ok(json_val) = serde_json::from_str::<serde_json::Value>(&response) {
|
||||
let pretty = serde_json::to_string_pretty(&json_val)?;
|
||||
fs::write("antares.json", pretty)?;
|
||||
let pretty = match serde_json::to_string_pretty(&json_val) {
|
||||
Ok(pretty) => pretty,
|
||||
Err(e) => {
|
||||
logger.log_error(&format!("Failed to serialize JSON: {}", e));
|
||||
return Err(Box::new(e));
|
||||
}
|
||||
};
|
||||
fs::write("antares.json", &pretty).map_err(|e| {
|
||||
logger.log_error(&format!("Failed to write antares.json: {}", e));
|
||||
Box::new(std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
|
||||
})?;
|
||||
logger.log_info("Response saved as JSON (schema mismatch)");
|
||||
} else {
|
||||
fs::write("antares.json", &response)?;
|
||||
|
|
|
|||
|
|
@ -40,10 +40,6 @@ impl Logger {
|
|||
));
|
||||
}
|
||||
|
||||
pub fn log_api_failure(&self, error: &str) {
|
||||
self.log(&format!("✗ API call failed: {}", error));
|
||||
}
|
||||
|
||||
pub fn log_export_success(&self, filepath: &str, row_count: usize) {
|
||||
self.log(&format!(
|
||||
"✓ Export successful - {} rows exported to {}",
|
||||
|
|
@ -58,4 +54,8 @@ impl Logger {
|
|||
pub fn log_info(&self, message: &str) {
|
||||
self.log(&format!("ℹ {}", message));
|
||||
}
|
||||
|
||||
pub fn log_error(&self, error: &str) {
|
||||
self.log(&format!("✗ Error: {}", error));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue