Move tile_scraper from examples to commands

This commit is contained in:
Tyler Hallada 2022-02-08 00:12:59 -05:00
parent b8c5f63aeb
commit 283cad220b
3 changed files with 17 additions and 6 deletions

View File

@ -1,11 +1,11 @@
use anyhow::Result; use anyhow::Result;
use reqwest::Client;
use std::fs::File; use std::fs::File;
use std::time::Duration; use std::time::Duration;
use tokio::time::sleep; use tokio::time::sleep;
#[tokio::main] pub async fn download_tiles(dir: &str) -> Result<()> {
pub async fn main() -> Result<()> { let client = Client::builder().build()?;
let client = reqwest::Client::builder().build()?;
for z in 10..18 { for z in 10..18 {
for x in 0..2_u32.pow(z - 9) { for x in 0..2_u32.pow(z - 9) {
for y 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?; let resp = client.get(&url).send().await?;
if resp.status().is_success() { if resp.status().is_success() {
println!("{}", url); println!("{}", url);
std::fs::create_dir_all(format!("tiles/{z}/{x}", z = z, x = x))?; std::fs::create_dir_all(format!("{}/{z}/{x}", dir, z = z, x = x))?;
let mut out = File::create(format!("tiles/{z}/{x}/{y}.jpg", z = z, x = x, y = y))?; let mut out =
File::create(format!("{}/{z}/{x}/{y}.jpg", dir, z = z, x = x, y = y))?;
let bytes = resp.bytes().await?; let bytes = resp.bytes().await?;
std::io::copy(&mut bytes.as_ref(), &mut out)?; std::io::copy(&mut bytes.as_ref(), &mut out)?;
} }

View File

@ -1,9 +1,11 @@
pub mod download_tiles;
pub mod dump_cell_data; pub mod dump_cell_data;
pub mod dump_cell_edit_counts; pub mod dump_cell_edit_counts;
pub mod dump_mod_data; pub mod dump_mod_data;
pub mod dump_mod_search_index; pub mod dump_mod_search_index;
pub mod update; pub mod update;
pub use download_tiles::download_tiles;
pub use dump_cell_data::dump_cell_data; pub use dump_cell_data::dump_cell_data;
pub use dump_cell_edit_counts::dump_cell_edit_counts; pub use dump_cell_edit_counts::dump_cell_edit_counts;
pub use dump_mod_data::dump_mod_data; pub use dump_mod_data::dump_mod_data;

View File

@ -12,7 +12,8 @@ mod nexus_scraper;
mod plugin_processor; mod plugin_processor;
use commands::{ 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)] #[derive(FromArgs)]
@ -37,6 +38,10 @@ struct Args {
/// file to output all mod titles and ids as a json search index /// file to output all mod titles and ids as a json search index
#[argh(option, short = 's')] #[argh(option, short = 's')]
mod_search_index: Option<String>, 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] #[tokio::main]
@ -64,6 +69,9 @@ pub async fn main() -> Result<()> {
if let Some(path) = args.mod_search_index { if let Some(path) = args.mod_search_index {
return dump_mod_search_index(&pool, &path).await; 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; return update(&pool, args.page).await;
} }