This commit is contained in:
Felipe 2025-12-20 19:01:40 -03:00
parent a34e3f8342
commit ed05e287b7
Signed by: pitbuster
SSH key fingerprint: SHA256:HDYu2Pm4/TmSX8GBwV49UvFWr1Ljg8XlHxKeCpjJpOk
7 changed files with 867 additions and 455 deletions

1170
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,32 @@
[package]
name = "ptcg-scrap"
name = "ptcg-tools"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.97"
clap = { version = "4.5.35", features = ["derive"] }
reqwest = { version = "0.12.15", default-features = false, features = ["http2", "rustls-tls"] }
scraper = "0.23.1"
strum = { version = "0.27.1", features = ["derive"] }
tokio = { version = "1.44.1", default-features = false, features = ["fs", "rt-multi-thread", "macros"] }
anyhow = "1.0.100"
camino = "1.2.2"
clap = { version = "4.5.53", features = ["derive"] }
directories = "6.0.0"
fluent-templates = "0.13.2"
reqwest = { version = "0.12.26", default-features = false, features = [
"brotli",
"http2",
"gzip",
"json",
"rustls-tls-native-roots",
"stream",
] }
serde = { version = "1.0.228", default-features = false, features = [
"derive",
"std",
] }
strum = { version = "0.27.2", features = ["derive"] }
tokio = { version = "1.48.0", default-features = false, features = ["fs", "rt-multi-thread", "macros"] }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.22", default-features = false, features = [
"fmt",
"json",
"env-filter",
] }

View file

@ -1 +1 @@
## PTCG Scrapper
## PTCG Tools

80
cliff.toml Normal file
View file

@ -0,0 +1,80 @@
[changelog]
# changelog header
header = """
# Changelog\n
"""
# template for the changelog body
# https://tera.netlify.app/docs
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
"""
# postprocessors
postprocessors = [
{ pattern = '<REPO>', replace = "https://oolong.ludwig.dog/pitbuster/ptcg-tools" },
]
[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = true
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))" }, # replace issue numbers
]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "Features" },
{ message = "^fix", group = "Bug Fixes" },
{ message = "^doc", group = "Documentation" },
{ message = "^chore(docs)", group = "Documentation" },
{ message = "^perf", group = "Performance" },
{ message = "^refactor", group = "Refactor" },
{ message = "^style", group = "Styling" },
{ message = "^test", group = "Testing" },
{ message = "^release:", skip = true },
{ message = "^chore\\(release\\):", skip = true },
{ message = "^chore\\(changelog\\):", skip = true },
{ message = "^chore\\(deps\\)", skip = true },
{ message = "^chore\\(pr\\)", skip = true },
{ message = "^chore\\(pull\\)", skip = true },
{ message = "^chore|ci", group = "Miscellaneous Tasks" },
{ body = ".*security", group = "Security" },
{ message = "^revert", group = "Revert" },
]
# extract external references
link_parsers = [
{ pattern = "#(\\d+)", href = "https://oolong.ludwig.dog/pitbuster/ptcg-tools/issues/$1" },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# glob pattern for matching git tags
tag_pattern = "[0-9]*"
# regex for skipping tags
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
# limit the number of commits included in the changelog.
# limit_commits = 42

32
src/logging.rs Normal file
View file

@ -0,0 +1,32 @@
use anyhow::{Result, anyhow};
use camino::Utf8PathBuf;
use directories::ProjectDirs;
use tracing_subscriber::Layer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
const APP_NAME: &str = "ptcg-tools";
/// Sets up logging for the application. Since the mode we will need logging for is a TUI, we can't
/// print our logs into stdout, so we will log into a file instead.
pub async fn initialize_logging() -> Result<()> {
let user_directory = ProjectDirs::from("cl", "bstr", APP_NAME)
.ok_or_else(|| anyhow!("failed to get ProjectDirs"))?
.data_dir()
.to_path_buf();
let user_directory = Utf8PathBuf::try_from(user_directory)?;
tokio::fs::create_dir_all(&user_directory).await?;
let log_path = user_directory.join(format!("{APP_NAME}.log"));
let log_file = std::fs::File::create(log_path)?;
let file_subscriber = tracing_subscriber::fmt::layer()
.with_file(true)
.with_line_number(true)
.with_writer(log_file)
.with_target(false)
.with_ansi(false)
.with_filter(tracing_subscriber::filter::EnvFilter::from(format!(
"{APP_NAME}=debug"
)));
tracing_subscriber::registry().with(file_subscriber).init();
Ok(())
}

View file

@ -8,10 +8,13 @@ pub mod cli;
pub mod downloader;
pub mod editions;
pub mod lang;
pub mod logging;
pub mod malie;
#[tokio::main]
async fn main() -> Result<()> {
let args = cli::Args::parse();
logging::initialize_logging().await?;
let client = reqwest::Client::new();
let edition =
editions::EditionCode::from_str(&args.code).context("Couldn't parse edition code")?;

1
src/malie/mod.rs Normal file
View file

@ -0,0 +1 @@
//! Module to interact with the PTCG data from malie.io