# ๐ Antares Data Exporter

**A powerful Rust utility for fetching Antares B2B product data and exporting to Excel**
[Features](#features) โข [Installation](#installation) โข [Usage](#usage) โข [Configuration](#configuration) โข [Architecture](#architecture)
---
## Overview
**Antares Data Exporter** is a high-performance Rust utility that seamlessly integrates with the Antares B2B web service to fetch product catalog data and export it to Excel with intelligent field mapping and business rule validation. Perfect for inventory management, data migration, and supply chain automation.
## โจ Features
- ๐ **Fast & Efficient** - Blocking HTTP client with 300-second timeout for reliable operations
- ๐ **Excel Export** - Intelligent field mapping with 8 carefully curated columns
- ๐ง **Smart Row Filtering** - Automatically skips incomplete records based on business rules
- ๐ **Dual Logging** - All events logged to both terminal and daily log files
- ๐ฏ **Flexible Output** - Support for custom file paths or directory-based exports
- ๐ **Secure Credentials** - Environment-based credential management, no hardcoding
- ๐๏ธ **Modular Architecture** - Clean separation of concerns for easy extension
- ๐ฆ **Auto Directory Creation** - Creates necessary directories on first run
## ๐ ๏ธ Technology Stack
- **Language:** Rust (2024 edition)
- **HTTP Client:** reqwest with blocking mode
- **Excel:** rust_xlsxwriter
- **Environment:** dotenv
- **Date/Time:** chrono
## ๐ Prerequisites
- Rust 1.70+ (with Cargo)
- Valid Antares B2B API credentials (usercode & password)
- Write access to create `log/`, `out/`, and `antares.json` at repo root
## ๐ฅ Installation
```bash
# Clone the repository
git clone https://github.com/yourusername/antares_get_data.git
cd antares_get_data
# Create .env from template
cp .env.example .env
# Configure your credentials
nano .env # or your favorite editor
```
## โ๏ธ Configuration
Edit `.env` with your Antares credentials and output preferences:
```env
# Antares B2B API credentials
ANTARES_USERCODE=your_usercode
ANTARES_PASSWORD=your_password_hash
# Output path for Excel file
# - Directory: Creates 'antares.xlsx' inside
# - File path (*.xlsx): Creates file at exact location
OUT=out
```
### OUT Path Examples
```env
OUT=out # โ out/antares.xlsx
OUT=exports/data.xlsx # โ exports/data.xlsx
OUT=/tmp/antares/report.xlsx # โ /tmp/antares/report.xlsx
```
## ๐ Usage
```bash
# Build the project
cargo build --release
# Run the data exporter
cargo run
# Or run the compiled binary directly
./target/release/antares_get_data
```
### What Happens on Execution
1. โ
**Initialization** - Logger created, output directory prepared
2. ๐ **Credential Loading** - Env vars validated and loaded
3. ๐ **API Request** - Fetches product data from Antares B2B (300s timeout)
4. ๐ **Data Processing** - Deserializes JSON into typed structs
5. ๐ **JSON Export** - Saves raw response to `antares.json`
6. ๐ **Excel Export** - Generates filtered, formatted Excel file
7. ๐ **Logging** - All events logged to `log/YYYY-MM-DD.log` + terminal
## ๐ Excel Output
The generated Excel file contains 8 columns of curated product data:
| Column | Source | Notes |
|--------|--------|-------|
| BESZCIKKSZAM | cikkszam | Product ID (required) |
| GYCIKKSZAM | cikkszam | Duplicate of BESZCIKKSZAM |
| BESZCIKKNEV | cikk_megnevezes_rovid / cikk_megnevezes | Product name (required) |
| GYARTO | Constant: "EGYEB" | Manufacturer code |
| CIKKAZON | vonalkod | Barcode (if available) |
| KESZLET | szabad_keszlet | Available stock |
| ME | mennyisegi_egyseg_kod | Unit of measure |
| EGYSEGAR | netto_kisker_ar / "Alap รกr" | Net unit price |
**Filtering Rules:**
- Rows are skipped if `BESZCIKKSZAM` is empty
- Rows are skipped if both `BESZCIKKNEV` sources are empty
- Product name prefers short form (`cikk_megnevezes_rovid`), falls back to full form
- Unit price prefers direct field; searches `cikk_jellemzok` for "Alap รกr" if zero
## ๐ Project Structure
```
antares_get_data/
โโโ src/
โ โโโ main.rs # Pipeline orchestration
โ โโโ api/
โ โ โโโ mod.rs
โ โ โโโ client.rs # Antares B2B URL builder
โ โโโ tools/
โ โ โโโ mod.rs
โ โ โโโ excel.rs # Excel export with field mapping
โ โ โโโ logger.rs # Dual-output logging system
โ โโโ template/
โ โโโ mod.rs
โ โโโ antares.rs # Serde models for API schema
โโโ .env.example # Configuration template
โโโ Cargo.toml # Rust dependencies
โโโ README.md # This file
```
## ๐๏ธ Architecture
### Modular Design
- **`src/api/client.rs`** - Builds Antares B2B API URLs
- **`src/tools/excel.rs`** - Intelligent Excel export with business rules
- **`src/tools/logger.rs`** - Dual logging (terminal + file) to `log/{YYYY-MM-DD}.log`
- **`src/template/antares.rs`** - Serde models matching Antares B2B schema
- **`src/main.rs`** - Clean orchestration without implementation details
### Pipeline Flow
```
Load Env Vars
โ
Initialize Logger
โ
Build API URL
โ
Fetch from Antares B2B (300s timeout)
โ
Deserialize JSON โ Save to antares.json
โ
Export Filtered Data โ Excel (with logging)
โ
Log Summary + Results
```
## ๐ Logging
All operations are logged to two destinations simultaneously:
**Terminal Output:**
```
[2026-04-30 16:30:15] โน Starting Antares data export
[2026-04-30 16:30:22] โ API call successful - Fetched 142 items
[2026-04-30 16:30:25] โ Export successful - 142 rows exported to out/antares_export.xlsx
```
**Log Files:** `log/2026-04-30.log` (daily rotation)
## ๐งช Development
```bash
# Format code
cargo fmt --all -- --check
# Lint with Clippy
cargo clippy --all-targets -- -D warnings
# Run tests
cargo test
# Build optimized release
cargo build --release
```
## ๐ฆ Generated Artifacts
After running, you'll find:
- **`antares.json`** - Full, pretty-printed API response
- **`out/antares_export.xlsx`** - Filtered Excel export (or custom path)
- **`log/YYYY-MM-DD.log`** - Daily operation log
All are automatically created and git-ignored.
## ๐ Security Notes
- โ
Credentials stored only in `.env` (git-ignored)
- โ
`.env.example` documents required variables without secrets
- โ
No hardcoded credentials in source code
- โ
API passwords transmitted over HTTPS only
## ๐ Troubleshooting
**Missing ANTARES_USERCODE error:**
```
Create .env file in repo root with:
ANTARES_USERCODE=your_code
ANTARES_PASSWORD=your_password
OUT=out
```
**Invalid OUT path error:**
```
Ensure OUT is either:
- A directory (created if missing): OUT=out
- A .xlsx file: OUT=export/data.xlsx
```
**API timeout:**
- Default timeout is 300 seconds (5 minutes)
- Check your network connection
- Verify Antares B2B service is available
## ๐ License
[Add your license here]
## ๐ค Contributing
Contributions welcome! Please follow the module structure and keep the architecture clean.
---
**Built with โค๏ธ for Antares B2B integration**