random command to satisfy my curiosity as to which map has the longest name
This commit is contained in:
61
src/main.rs
61
src/main.rs
@@ -24,6 +24,7 @@ enum Commands{
|
||||
UploadScripts(UploadScriptsCommand),
|
||||
DeleteScriptPolicy(DeleteScriptPolicyCommand),
|
||||
BackupMapfixes(BackupMapfixesCommand),
|
||||
LongestDisplayName(LongestDisplayNameCommand),
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@@ -69,6 +70,13 @@ struct BackupMapfixesCommand{
|
||||
#[arg(long)]
|
||||
api_url:String,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct LongestDisplayNameCommand{
|
||||
#[arg(long)]
|
||||
session_id_file:PathBuf,
|
||||
#[arg(long)]
|
||||
api_url:String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main(){
|
||||
@@ -99,6 +107,10 @@ async fn main(){
|
||||
session_id:std::fs::read_to_string(command.session_id_file).unwrap(),
|
||||
api_url:command.api_url,
|
||||
}).await.unwrap(),
|
||||
Commands::LongestDisplayName(command)=>longest_display_name(LongestDisplayNameConfig{
|
||||
session_id:std::fs::read_to_string(command.session_id_file).unwrap(),
|
||||
api_url:command.api_url,
|
||||
}).await.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1021,3 +1033,52 @@ async fn backup_maps(config:BackupMapfixesConfig)->Result<(),BackupMapfixesError
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
struct LongestDisplayNameConfig{
|
||||
session_id:String,
|
||||
api_url:String,
|
||||
}
|
||||
#[expect(unused)]
|
||||
#[derive(Debug)]
|
||||
enum LongestDisplayNameError{
|
||||
Cookie(submissions_api::CookieError),
|
||||
Reqwest(submissions_api::ReqwestError),
|
||||
GetMaps(submissions_api::Error),
|
||||
Json(serde_json::Error),
|
||||
Io(std::io::Error),
|
||||
}
|
||||
async fn longest_display_name(config:LongestDisplayNameConfig)->Result<(),LongestDisplayNameError>{
|
||||
let cookie=submissions_api::Cookie::new(&config.session_id).map_err(LongestDisplayNameError::Cookie)?;
|
||||
let api=&submissions_api::external::Context::new(config.api_url,cookie).map_err(LongestDisplayNameError::Reqwest)?;
|
||||
|
||||
//download all maps
|
||||
let mut maps=Vec::new();
|
||||
let mut page=1;
|
||||
loop{
|
||||
const LIMIT:u32=100;
|
||||
let maps_page=api.get_maps(submissions_api::types::GetMapsRequest{
|
||||
Page:page,
|
||||
Limit:LIMIT,
|
||||
DisplayName:None,
|
||||
Creator:None,
|
||||
GameID:None,
|
||||
Sort:None,
|
||||
}).await.map_err(LongestDisplayNameError::GetMaps)?;
|
||||
let len=maps_page.len();
|
||||
maps.extend(maps_page);
|
||||
if len<LIMIT as usize{
|
||||
break;
|
||||
}else{
|
||||
page+=1;
|
||||
}
|
||||
}
|
||||
|
||||
maps.sort_by_key(|map|map.DisplayName.chars().count());
|
||||
|
||||
for map in maps.iter().rev().take(10){
|
||||
dbg!(map);
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user