1
Fork 0

Add Serde, JSON and SteamApp stuff.

This commit is contained in:
Bauke 2022-09-22 18:42:44 +02:00
parent e543f0aac0
commit 252fb17d56
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 62 additions and 0 deletions

25
Cargo.lock generated
View File

@ -306,6 +306,12 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "itoa"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
[[package]] [[package]]
name = "jetscii" name = "jetscii"
version = "0.5.3" version = "0.5.3"
@ -505,6 +511,12 @@ dependencies = [
"webpki", "webpki",
] ]
[[package]]
name = "ryu"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]] [[package]]
name = "sct" name = "sct"
version = "0.7.0" version = "0.7.0"
@ -535,6 +547,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "serde_json"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]] [[package]]
name = "sharded-slab" name = "sharded-slab"
version = "0.1.4" version = "0.1.4"
@ -559,6 +582,8 @@ dependencies = [
"indicatif", "indicatif",
"opml", "opml",
"regex", "regex",
"serde",
"serde_json",
"ureq", "ureq",
] ]

View File

@ -16,6 +16,8 @@ color-eyre = "0.6.2"
indicatif = "0.17.1" indicatif = "0.17.1"
opml = "1.1.4" opml = "1.1.4"
regex = "1.6.0" regex = "1.6.0"
serde = "1.0.144"
serde_json = "1.0.85"
ureq = "2.5.0" ureq = "2.5.0"
[dependencies.clap] [dependencies.clap]

View File

@ -14,6 +14,8 @@ use {
color_eyre::{install, Result}, color_eyre::{install, Result},
indicatif::{ProgressBar, ProgressStyle}, indicatif::{ProgressBar, ProgressStyle},
regex::Regex, regex::Regex,
serde::Deserialize,
serde_json::Value,
}; };
/// CLI arguments struct using [`clap`]'s Derive API. /// CLI arguments struct using [`clap`]'s Derive API.
@ -39,11 +41,19 @@ pub struct Args {
/// A game's store URL, can be used multiple times. /// A game's store URL, can be used multiple times.
#[clap(long)] #[clap(long)]
pub url: Vec<String>, pub url: Vec<String>,
/// A person's steamcommunity.com ID or full URL, can be used multiple times.
#[clap(long)]
pub user: Vec<String>,
} }
/// A simple feed struct. /// A simple feed struct.
#[derive(Debug)] #[derive(Debug)]
pub struct Feed { pub struct Feed {
/// A potential alternate friendly URL, see [`SteamApp::friendly_url`] for an
/// explanation.
pub friendly_url: Option<String>,
/// The text to use for the feed in the OPML output. /// The text to use for the feed in the OPML output.
pub text: Option<String>, pub text: Option<String>,
@ -51,6 +61,29 @@ pub struct Feed {
pub url: String, pub url: String,
} }
/// A small representation of a Steam game that is parsed from JSON.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SteamApp {
/// The AppID of the game.
pub appid: usize,
/// The name of the game.
pub name: String,
/// A friendly URL name of the game, some feeds will use this instead of their
/// AppID for their RSS feed.
///
/// For example, [Portal's feed](https://steamcommunity.com/games/Portal/rss)
/// uses `Portal`, instead of
/// [its AppID 400](https://steamcommunity.com/games/400/rss).
///
/// Some games may also have a friendly URL different from their AppID but
/// don't use it for their feed. Steam is weird.
#[serde(rename = "friendlyURL")]
pub friendly_url: Value,
}
fn main() -> Result<()> { fn main() -> Result<()> {
install()?; install()?;
@ -68,6 +101,7 @@ fn main() -> Result<()> {
for appid in args.appid { for appid in args.appid {
potential_feeds.push(Feed { potential_feeds.push(Feed {
friendly_url: None,
text: Some(format!("Steam AppID {appid}")), text: Some(format!("Steam AppID {appid}")),
url: appid_to_rss_url(appid), url: appid_to_rss_url(appid),
}); });
@ -80,6 +114,7 @@ fn main() -> Result<()> {
.and_then(|appid_match| appid_match.as_str().parse::<usize>().ok()); .and_then(|appid_match| appid_match.as_str().parse::<usize>().ok());
if let Some(appid) = appid { if let Some(appid) = appid {
potential_feeds.push(Feed { potential_feeds.push(Feed {
friendly_url: None,
text: Some(format!("Steam AppID {appid}")), text: Some(format!("Steam AppID {appid}")),
url: appid_to_rss_url(appid), url: appid_to_rss_url(appid),
}); });