~misterio/sistemer-bot

03ce4ddf3107f0d1b9a81fa915b27bd310e1414c — Gabriel Fontes 2 years ago 839d590 1.1.2
permite ignorar acentos ao buscar disciplina
5 files changed, 32 insertions(+), 9 deletions(-)

M Cargo.lock
M Cargo.nix
M Cargo.toml
M flake.nix
M src/disciplina.rs
M Cargo.lock => Cargo.lock +8 -1
@@ 1135,7 1135,7 @@ dependencies = [

[[package]]
name = "sistemer-bot"
version = "1.1.1"
version = "1.1.2"
dependencies = [
 "anyhow",
 "chrono",


@@ 1146,6 1146,7 @@ dependencies = [
 "reqwest",
 "teloxide",
 "tokio",
 "unidecode",
]

[[package]]


@@ 1453,6 1454,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

[[package]]
name = "unidecode"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "402bb19d8e03f1d1a7450e2bd613980869438e0666331be3e073089124aa1adc"

[[package]]
name = "url"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

M Cargo.nix => Cargo.nix +15 -1
@@ 3146,7 3146,7 @@ rec {
      };
      "sistemer-bot" = rec {
        crateName = "sistemer-bot";
        version = "1.1.1";
        version = "1.1.2";
        edition = "2018";
        crateBin = [
          { name = "sistemer-bot"; path = "src/main.rs"; }


@@ 3191,6 3191,10 @@ rec {
            packageId = "tokio";
            features = [ "rt-multi-thread" "macros" ];
          }
          {
            name = "unidecode";
            packageId = "unidecode";
          }
        ];

      };


@@ 4093,6 4097,16 @@ rec {
        };
        resolvedDefaultFeatures = [ "default" ];
      };
      "unidecode" = rec {
        crateName = "unidecode";
        version = "0.3.0";
        edition = "2015";
        sha256 = "1p0sm8j9223kw3iincv60s746s88k09xcaqf8nkx3w83isfv2as0";
        authors = [
          "Amit Chowdhury <amitc97@gmail.com>"
        ];

      };
      "url" = rec {
        crateName = "url";
        version = "2.2.2";

M Cargo.toml => Cargo.toml +2 -1
@@ 1,6 1,6 @@
[package]
name = "sistemer-bot"
version = "1.1.1"
version = "1.1.2"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


@@ 15,3 15,4 @@ reqwest = "0.11"
anyhow = "1.0"
regex = "1.5"
chrono = "0.4"
unidecode = "0.3"

M flake.nix => flake.nix +5 -4
@@ 23,13 23,14 @@
      devShell = pkgs.mkShell {
        buildInputs = with pkgs;
          [
            rustc
            cargo
            rust-analyzer
            rustfmt
            clippy
            pkgconfig
            crate2nix
            openssl
            pkgconfig
            rust-analyzer
            rustc
            rustfmt
          ];
      };
    }

M src/disciplina.rs => src/disciplina.rs +2 -2
@@ 7,13 7,13 @@ pub async fn get_disciplina(disciplina: &str) -> Result<String> {
        .text()
        .await?;

    let start_pattern = Regex::new(&format!("<h2.*{}.*</h2>", disciplina.to_lowercase()))?;
    let start_pattern = Regex::new(&format!("<h2.*{}.*</h2>", unidecode::unidecode(&disciplina.to_lowercase())))?;
    let stop_pattern = Regex::new("<hr />")?;

    let mut output: String = "".into();
    let mut adding = false;
    for line in fulltext.lines() {
        if start_pattern.is_match(&line.to_lowercase()) {
        if start_pattern.is_match(&unidecode::unidecode(&line.to_lowercase())) {
            output.push_str(&crate::sanitize_line(line, false)?);
            adding = true;
        } else if adding {