Move tile_scraper from examples to commands
This commit is contained in:
parent
b8c5f63aeb
commit
283cad220b
@ -1,11 +1,11 @@
|
||||
use anyhow::Result;
|
||||
use reqwest::Client;
|
||||
use std::fs::File;
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> Result<()> {
|
||||
let client = reqwest::Client::builder().build()?;
|
||||
pub async fn download_tiles(dir: &str) -> Result<()> {
|
||||
let client = Client::builder().build()?;
|
||||
for z in 10..18 {
|
||||
for x in 0..2_u32.pow(z - 9) {
|
||||
for y in 0..2_u32.pow(z - 9) {
|
||||
@ -19,8 +19,9 @@ pub async fn main() -> Result<()> {
|
||||
let resp = client.get(&url).send().await?;
|
||||
if resp.status().is_success() {
|
||||
println!("{}", url);
|
||||
std::fs::create_dir_all(format!("tiles/{z}/{x}", z = z, x = x))?;
|
||||
let mut out = File::create(format!("tiles/{z}/{x}/{y}.jpg", z = z, x = x, y = y))?;
|
||||
std::fs::create_dir_all(format!("{}/{z}/{x}", dir, z = z, x = x))?;
|
||||
let mut out =
|
||||
File::create(format!("{}/{z}/{x}/{y}.jpg", dir, z = z, x = x, y = y))?;
|
||||
let bytes = resp.bytes().await?;
|
||||
std::io::copy(&mut bytes.as_ref(), &mut out)?;
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
pub mod download_tiles;
|
||||
pub mod dump_cell_data;
|
||||
pub mod dump_cell_edit_counts;
|
||||
pub mod dump_mod_data;
|
||||
pub mod dump_mod_search_index;
|
||||
pub mod update;
|
||||
|
||||
pub use download_tiles::download_tiles;
|
||||
pub use dump_cell_data::dump_cell_data;
|
||||
pub use dump_cell_edit_counts::dump_cell_edit_counts;
|
||||
pub use dump_mod_data::dump_mod_data;
|
||||
|
10
src/main.rs
10
src/main.rs
@ -12,7 +12,8 @@ mod nexus_scraper;
|
||||
mod plugin_processor;
|
||||
|
||||
use commands::{
|
||||
dump_cell_data, dump_cell_edit_counts, dump_mod_data, dump_mod_search_index, update,
|
||||
download_tiles, dump_cell_data, dump_cell_edit_counts, dump_mod_data, dump_mod_search_index,
|
||||
update,
|
||||
};
|
||||
|
||||
#[derive(FromArgs)]
|
||||
@ -37,6 +38,10 @@ struct Args {
|
||||
/// file to output all mod titles and ids as a json search index
|
||||
#[argh(option, short = 's')]
|
||||
mod_search_index: Option<String>,
|
||||
|
||||
/// folder to output all map tile images downloaded from the UESP wiki
|
||||
#[argh(option, short = 't')]
|
||||
download_tiles: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@ -64,6 +69,9 @@ pub async fn main() -> Result<()> {
|
||||
if let Some(path) = args.mod_search_index {
|
||||
return dump_mod_search_index(&pool, &path).await;
|
||||
}
|
||||
if let Some(dir) = args.download_tiles {
|
||||
return download_tiles(&dir).await;
|
||||
}
|
||||
|
||||
return update(&pool, args.page).await;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user