mirror of
https://github.com/bvanroll/unnamed_chatgpt_project.git
synced 2025-08-29 12:02:45 +00:00
interessant projectjen
This commit is contained in:
12
data_prep/Cargo.toml
Normal file
12
data_prep/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "data_prep"
|
||||
version = "0.1.0"
|
||||
authors = ["bvanroll <beppe.vanrolleghem@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rfd = "0.10.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.91"
|
42
data_prep/src/main.rs
Normal file
42
data_prep/src/main.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use serde::{Serialize};
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct MiniHuman {
|
||||
name: String,
|
||||
gender: String,
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let mut miniHumans:Vec<MiniHuman> = Vec::new();
|
||||
let current_path = std::env::current_dir().unwrap();
|
||||
let res = rfd::FileDialog::new().set_directory(¤t_path).pick_file().unwrap();
|
||||
let file = File::open(res.as_path()).unwrap();
|
||||
let reader = BufReader::new(file);
|
||||
for buffer in reader.lines() {
|
||||
if let Ok(line) = buffer {
|
||||
//# = comment
|
||||
// let mut chars = line.chars();
|
||||
// let mut gender:String = String::from(chars.next().unwrap());
|
||||
// if gender != "?" && gender != "F" && gender != "M" { continue; }
|
||||
// if gender == "?" {
|
||||
// let preference = chars.next().unwrap();
|
||||
// gender = gender + &*(preference).to_string();
|
||||
// }
|
||||
let mut parts = line.split(" ");
|
||||
let gender = parts.next().unwrap().to_string();
|
||||
if gender.chars().next().unwrap() == '#' { continue; }
|
||||
parts.next();
|
||||
let mut name = parts.next().unwrap().to_string();
|
||||
name = name.replace("+", " ");
|
||||
miniHumans.push(MiniHuman{name: name, gender: gender})
|
||||
}
|
||||
|
||||
}
|
||||
let serialized: String = serde_json::to_string(&miniHumans).unwrap();
|
||||
let save_res = rfd::FileDialog::new().set_directory(¤t_path).save_file().unwrap();
|
||||
let mut file = File::create(save_res.as_path()).unwrap();
|
||||
file.write_all(serialized.as_bytes()).expect("oopsie");
|
||||
}
|
Reference in New Issue
Block a user