From 3836ccfb9f8b9aef657d6b936320d03bdb9cbbea Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 26 Nov 2023 00:22:48 -0500 Subject: [PATCH] Add hyperlink to video game in start.gg --- src/datasets.rs | 22 ++++++++++++++-------- src/main.rs | 23 ++++++++++------------- src/queries/search_games.rs | 3 +++ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/datasets.rs b/src/datasets.rs index 06f19b7..264a600 100644 --- a/src/datasets.rs +++ b/src/datasets.rs @@ -11,6 +11,7 @@ pub struct DatasetMetadata { pub game_id: VideogameId, pub game_name: String, + pub game_slug: String, pub country: Option, pub state: Option, @@ -47,6 +48,7 @@ CREATE TABLE IF NOT EXISTS datasets ( last_sync INTEGER NOT NULL, game_id INTEGER NOT NULL, game_name TEXT NOT NULL, + game_slug TEXT NOT NULL, country TEXT, state TEXT, set_limit INTEGER NOT NULL, @@ -87,6 +89,7 @@ pub fn list_datasets(connection: &Connection) -> sqlite::Result("last_sync") as u64), game_id: VideogameId(r_.read::("game_id") as u64), game_name: r_.read::<&str, _>("game_name").to_owned(), + game_slug: r_.read::<&str, _>("game_slug").to_owned(), country: r_.read::, _>("country").map(String::from), state: r_.read::, _>("state").map(String::from), set_limit: r_.read::("set_limit") as u64, @@ -117,7 +120,7 @@ pub fn new_dataset( dataset: &str, metadata: DatasetMetadata, ) -> sqlite::Result<()> { - let query1 = r#"INSERT INTO datasets VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"#; + let query1 = r#"INSERT INTO datasets VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"#; let query2 = format!( r#"CREATE TABLE "{0}_players" ( id INTEGER PRIMARY KEY, @@ -176,13 +179,14 @@ CREATE VIEW "{0}_view" .bind((2, metadata.last_sync.0 as i64))? .bind((3, metadata.game_id.0 as i64))? .bind((4, &metadata.game_name[..]))? - .bind((5, metadata.country.as_deref()))? - .bind((6, metadata.state.as_deref()))? - .bind((7, metadata.set_limit as i64))? - .bind((8, metadata.decay_rate))? - .bind((9, metadata.adj_decay_rate))? - .bind((10, metadata.period))? - .bind((11, metadata.tau))? + .bind((5, &metadata.game_slug[..]))? + .bind((6, metadata.country.as_deref()))? + .bind((7, metadata.state.as_deref()))? + .bind((8, metadata.set_limit as i64))? + .bind((9, metadata.decay_rate))? + .bind((10, metadata.adj_decay_rate))? + .bind((11, metadata.period))? + .bind((12, metadata.tau))? .try_for_each(|x| x.map(|_| ()))?; connection.execute(query2) @@ -205,6 +209,7 @@ pub fn get_metadata( last_sync: Timestamp(r_.read::("last_sync") as u64), game_id: VideogameId(r_.read::("game_id") as u64), game_name: r_.read::<&str, _>("game_name").to_owned(), + game_slug: r_.read::<&str, _>("game_slug").to_owned(), country: r_.read::, _>("country").map(String::from), state: r_.read::, _>("state").map(String::from), set_limit: r_.read::("set_limit") as u64, @@ -579,6 +584,7 @@ CREATE TABLE IF NOT EXISTS datasets ( last_sync: Timestamp(1), game_id: VideogameId(0), game_name: String::from("Test Game"), + game_slug: String::from("test"), country: None, state: None, set_limit: 0, diff --git a/src/main.rs b/src/main.rs index 789906b..1503e08 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,25 +115,20 @@ fn dataset_list() { let datasets = list_datasets(&connection).expect("Error communicating with SQLite"); for (name, metadata) in datasets { - println!(); + print!( + "\n\x1b[1m\x1b[4m{}\x1b[0m - \ +\x1b]8;;https://www.start.gg/{}\x1b\\{}\x1b]8;;\x1b\\ ", + name, metadata.game_slug, metadata.game_name + ); if let Some(country) = metadata.country { if let Some(state) = metadata.state { - println!( - "\x1b[1m\x1b[4m{}\x1b[0m - {} (in {}, {})", - name, metadata.game_name, country, state - ); + println!("(in {}, {})", country, state); } else { - println!( - "\x1b[1m\x1b[4m{}\x1b[0m - {} (in {})", - name, metadata.game_name, country - ); + println!("(in {})", country); } } else { - println!( - "\x1b[1m\x1b[4m{}\x1b[0m - {} (Global)", - name, metadata.game_name - ); + println!("(Global)"); } let current_time = SystemTime::now() @@ -222,6 +217,7 @@ fn dataset_new(name: Option, auth_token: Option) { let VideogameData { id: game_id, name: game_name, + slug: game_slug, } = games[index].clone(); // Location @@ -407,6 +403,7 @@ Tau constant (default 0.4): " last_sync: Timestamp(1), game_id, game_name, + game_slug, country, state, set_limit, diff --git a/src/queries/search_games.rs b/src/queries/search_games.rs index 1d40643..af88dee 100644 --- a/src/queries/search_games.rs +++ b/src/queries/search_games.rs @@ -28,6 +28,7 @@ struct VideogameConnection { struct Videogame { id: Option, name: Option, + slug: Option, } // Unwrapping @@ -36,6 +37,7 @@ struct Videogame { pub struct VideogameData { pub id: VideogameId, pub name: String, + pub slug: String, } impl<'a> QueryUnwrap> for VideogameSearch { @@ -52,6 +54,7 @@ impl<'a> QueryUnwrap> for VideogameSearch { Some(VideogameData { id: game.id?, name: game.name?, + slug: game.slug?, }) }) .collect(),