2022-02-08 05:02:26 +00:00
|
|
|
use anyhow::Result;
|
2022-06-04 04:50:11 +00:00
|
|
|
use chrono::NaiveDateTime;
|
2022-02-08 05:02:26 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
2022-06-04 22:51:20 +00:00
|
|
|
use tracing::info;
|
2022-02-08 05:02:26 +00:00
|
|
|
|
|
|
|
use crate::models::game_mod;
|
|
|
|
|
2022-06-04 04:50:11 +00:00
|
|
|
pub async fn dump_mod_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, updated_after: Option<NaiveDateTime>) -> Result<()> {
|
2022-06-04 22:51:20 +00:00
|
|
|
let mut page = 1;
|
2022-02-08 05:02:26 +00:00
|
|
|
let page_size = 20;
|
|
|
|
let mut last_id = None;
|
|
|
|
loop {
|
|
|
|
let mods =
|
2022-06-05 06:58:11 +00:00
|
|
|
game_mod::batched_get_with_cells_and_files(&pool, page_size, last_id, "Skyrim.esm", 1, updated_after).await?;
|
2022-02-08 05:02:26 +00:00
|
|
|
if mods.is_empty() {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for mod_with_cells in mods {
|
|
|
|
let path = Path::new(&dir);
|
|
|
|
std::fs::create_dir_all(&path)?;
|
|
|
|
let path = path.join(format!("{}.json", mod_with_cells.nexus_mod_id));
|
2022-06-04 22:51:20 +00:00
|
|
|
info!(page = page, nexus_mod_id = mod_with_cells.nexus_mod_id, "dumping mod data to {}", path.display());
|
2022-02-08 05:02:26 +00:00
|
|
|
let mut file = File::create(path)?;
|
|
|
|
write!(file, "{}", serde_json::to_string(&mod_with_cells)?)?;
|
|
|
|
last_id = Some(mod_with_cells.id);
|
|
|
|
}
|
2022-06-04 22:51:20 +00:00
|
|
|
page += 1;
|
2022-02-08 05:02:26 +00:00
|
|
|
}
|
|
|
|
return Ok(());
|
|
|
|
}
|