Added new export record, path building and sql script to get data.

This commit is contained in:
2025-06-10 02:31:23 +02:00
parent 0a7d72825f
commit ba7e512bb3
2 changed files with 55 additions and 14 deletions
+45 -14
View File
@@ -1,6 +1,17 @@
use std::fs::File;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
struct ExportRecord {
product_id: String,
name: Option<String>,
attr1: Option<String>,
path: String,
shop_name: Option<String>,
host: Option<String>,
subshop_id: Option<String>,
}
#[derive(Deserialize, Serialize, Debug)]
struct Record {
source_url: String,
@@ -18,31 +29,51 @@ fn main() -> Result<(), csv::Error> {
let mut records: Vec<Record> = Vec::new();
for result in rdr.deserialize() {
let mut record: Record = result?;
//println!("{:?}", record);
let record: ExportRecord = result?;
println!("{:?}", record);
let mut temp_target_url: Vec<String> = record.source_url.split("/").map(|s| s.to_string()).collect();
let mut temp_target_url: Vec<String> = record.path.split("/").map(|s| s.to_string()).collect();
// Modify to new target url
temp_target_url.remove(temp_target_url.len() - 2); // Remove number before product name
if temp_target_url[0].eq("gewuerze") {
temp_target_url.remove(0);
}
temp_target_url.insert(0, String::from("public/lgw")); // For testing environment
temp_target_url.remove(temp_target_url.len() - 2); // Remove number before product name
if !record.attr1.clone().unwrap().eq("NULL") {
temp_target_url.push(record.attr1.unwrap()); // Add article number if not null
}
// Combine to new target url
let target_url = temp_target_url.join("/");
record.target_url = Some(target_url);
record.http_code = Some("301".to_string());
record.enabled = Some("1".to_string());
record.query_params_handling = Some("0".to_string());
record.sales_channel_id = Some("".to_string());
records.push(record)
// Build source url
let mut source_url_vec: Vec<String> = Vec::new();
source_url_vec.insert(0, String::from("public/lgw")); // For testing environment
source_url_vec.push(record.path);
// Combine source url
let source_url = source_url_vec.join("/");
records.push(Record{
source_url,
target_url: Some(target_url),
http_code: Some("301".to_string()),
enabled: Some("1".to_string()),
query_params_handling: Some("".to_string()),
sales_channel_id: Some("".to_string()),
})
}
let new_csv = File::create("redirects.csv")?;
let mut wtr = csv::Writer::from_writer(new_csv);
let mut wtr = csv::WriterBuilder::new()
.delimiter(b';')
.from_writer(new_csv);
for record in records {
wtr.serialize(record)?;