StartRNR/cli/src/main.rs

66 lines
1.7 KiB
Rust
Raw Normal View History

#![feature(iterator_try_collect)]
use futures::executor::block_on;
2023-08-27 03:02:18 -04:00
use std::io::{self, Write};
use std::path::Path;
2023-08-26 23:47:23 -04:00
2023-08-26 23:48:13 -04:00
mod queries;
2023-08-27 03:52:38 -04:00
use queries::*;
2023-08-26 23:48:13 -04:00
2023-08-27 05:26:11 -04:00
mod datasets;
2023-08-26 23:48:13 -04:00
2023-08-27 03:02:18 -04:00
fn get_auth_key(config_dir: &Path) -> Option<String> {
use std::env::{var, VarError};
use std::fs::read_to_string;
match var("AUTH_KEY") {
Ok(key) => Some(key),
Err(VarError::NotUnicode(_)) => panic!("Invalid authorization key"),
Err(VarError::NotPresent) => {
let mut auth_file = config_dir.to_owned();
auth_file.push("auth.txt");
2023-08-28 00:57:20 -04:00
read_to_string(auth_file).ok().and_then(|s| {
let trimmed = s.trim();
if trimmed.is_empty() {
None
} else {
Some(trimmed.to_owned())
}
})
2023-08-27 03:02:18 -04:00
}
}
}
2023-08-26 03:37:24 -04:00
fn main() {
2023-08-27 03:02:18 -04:00
let mut config_dir = dirs::config_dir().unwrap();
config_dir.push("ggelo");
let auth_key = get_auth_key(&config_dir).expect("Could not find authorization key");
2023-08-28 00:57:20 -04:00
if let Some(response) = block_on(run_query::<TournamentSets, _>(
TournamentSetsVars {
last_query: None,
game_id: VideogameId(1386),
country: None,
state: Some("GA"),
},
&auth_key,
)) {
2023-08-28 00:57:20 -04:00
println!("Succeeded");
for tournament in response {
println!("Tournament: {}", tournament.name);
for set in tournament.sets {
println!(
"Winner: {}",
if set.winner {
set.player2.0
} else {
set.player1.0
}
);
}
2023-08-27 03:02:18 -04:00
}
} else {
2023-08-28 00:57:20 -04:00
println!("Invalid GraphQL response");
2023-08-27 03:02:18 -04:00
}
2023-08-26 03:37:24 -04:00
}