Skip to content

Commit

Permalink
Merge pull request #8 from josueBarretogit/get-data-crates-from-json
Browse files Browse the repository at this point in the history
Get data crates from json
  • Loading branch information
josueBarretogit authored May 25, 2024
2 parents 89cb515 + bcca807 commit 3571bcf
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 1,547 deletions.
345 changes: 9 additions & 336 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ categories = ["utilities", "development-tools" , "command-line", "dependencies"]
license = "MIT"

[dependencies]
reqwest = "0.12.4"
reqwest = { version = "0.12.4" , features = ["json"]}
ratatui = { version = "0.26.3", features = ["all-widgets"] }
color-eyre = "0.6.2"
crossterm = { version = "0.27.0", features = ["event-stream"] }
serde = { version = "1.0.200", features = ["derive"] }
strum = "0.26.2"
strum_macros = "0.26"
scraper = "0.19.0"
open = "5.1.3"
throbber-widgets-tui = "0.5.0"
tokio = { version = "1.37.0", features = ["full"] }
16 changes: 8 additions & 8 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ pub struct Table {
pub entries: Vec<TableEntry>,
}

impl Into<Vec<CrateItemList>> for crate::backend::Table {
fn into(self) -> Vec<CrateItemList> {
impl From<crate::backend::Table> for Vec<CrateItemList> {
fn from(val: crate::backend::Table) -> Self {
let mut items: Vec<CrateItemList> = vec![];

self.entries.iter().for_each(|entr| {
val.entries.iter().for_each(|entr| {
entr.crates.iter().for_each(|cr| {
items.push(CrateItemList::new(
cr.name.to_owned(),
cr.description.to_owned(),
cr.name.clone(),
cr.description.clone(),
ItemListStatus::default(),
cr.features.to_owned(),
))
})
cr.features.clone(),
));
});
});

items
Expand Down
73 changes: 63 additions & 10 deletions src/content_parser.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@
use crate::backend::{Categories, CategoriesWithSubCategories, Crates, Table, TableEntry};
use crate::scraper::scraper::Group;

pub mod content_parser;

#[cfg(test)]
pub trait ContentParser {
fn get_general_crates(&self) -> Table;

fn get_crates(&self, category: &Categories) -> Table;

fn get_crates_with_sub(&self, category: &CategoriesWithSubCategories) -> Table;
}

impl From<&Group> for Table {
fn from(value: &Group) -> Self {
let mut entries: Vec<TableEntry> = Vec::new();

//This means this is parsing a category with 1 table
if let Some(purposes) = &value.purposes {
for purpose in purposes {
let mut crates: Vec<Crates> = Vec::new();

for recommendation in &purpose.recommendations {
crates.push(Crates {
name: recommendation.name.clone(),
description: recommendation
.notes
.clone()
.unwrap_or("No description".to_string()),
features: None,
});
}

entries.push(TableEntry {
use_case: String::default(),
crates,
});
}

mod test {
use crate::{
backend::{Crates, Table, TableEntry},
content_parser::content_parser::ContentParser,
};
return Table { entries };
};

#[test]
fn general_table_has_expected_data() {
//I dont know how to test this xd
todo!()
//Parsing a category with multiple tables
if let Some(subgroups) = &value.subgroups {
for subgroup in subgroups {
let mut crates: Vec<Crates> = Vec::new();
if let Some(purposes) = &subgroup.purposes {
for purpose in purposes {
purpose.recommendations.iter().for_each(|recommendation| {
crates.push(Crates {
name: recommendation.name.clone(),
description: recommendation
.notes
.clone()
.unwrap_or("No description".to_string()),
features: None,
});
});
}
}
entries.push(TableEntry {
use_case: String::default(),
crates,
});
}
};
Table { entries }
}
}
Loading

0 comments on commit 3571bcf

Please sign in to comment.