Skip to content

Commit

Permalink
Improved packaging (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecardleitao authored Nov 20, 2023
1 parent 188996e commit 09a4c48
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ name = "flights"
version = "0.1.0"
edition = "2021"

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

[dependencies]
tinytemplate = "1.1"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "*"
serde_json = "*"
clap = { version = "4.4.6", features = ["derive"] }

# process JSON from https
serde_json = { version = "1.0", default_features = false }

# perform requests to the internet
reqwest = {version="*", features = ["blocking", "gzip"]}

# create random string for cookies
rand = {version="*", default_features = false, features = ["std", "std_rng", "getrandom"]}

#
# to perform time-based calculations
time = {version="*", default_features = false, features = ["formatting", "parsing", "macros"]}

# compute distances between geo-points
geoutils = "*"
geoutils = {version="*", default_features = false}

# read airport names
csv = "*"
csv = {version="*", default_features = false}

[dev-dependencies]
tinytemplate = "1.1"
clap = { version = "4.4.6", features = ["derive"] }
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ private jet's flight information targetted to a Danish audience.
## How to use

1. Install Rust
2. run `cargo run -- --tail-number "OY-GFS" --date "2023-10-20"`
2. run `cargo run --example single_day -- --tail-number "OY-GFS" --date "2023-10-20"`
3. open `OY-GFS_2023-10-20_0.md`

## Assumptions

Expand Down
2 changes: 1 addition & 1 deletion examples/period.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Context {
fn render(context: &Context) -> Result<(), Box<dyn Error>> {
let path = "story.md";

let template = std::fs::read_to_string("examples/template.md")?;
let template = std::fs::read_to_string("examples/period_template.md")?;

let mut tt = tinytemplate::TinyTemplate::new();
tt.set_default_formatter(&tinytemplate::format_unescaped);
Expand Down
File renamed without changes.
23 changes: 22 additions & 1 deletion src/main.rs → examples/single_day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ use clap::Parser;

static TEMPLATE_NAME: &'static str = "t";

#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct Event {
pub tail_number: String,
pub owner: Fact<Company>,
pub date: String,
pub from_airport: String,
pub to_airport: String,
pub two_way: bool,
pub commercial_emissions_kg: Fact<usize>,
pub emissions_kg: Fact<usize>,
pub source: String,
pub source_date: String,
}

#[derive(serde::Serialize)]
pub struct Context {
pub event: Event,
pub dane_emissions_kg: Fact<usize>,
pub dane_years: String,
}

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -103,7 +124,7 @@ fn process_leg(
dane_years,
};

let template = std::fs::read_to_string("src/template.md")?;
let template = std::fs::read_to_string("examples/single_day_template.md")?;

let mut tt = TinyTemplate::new();
tt.set_default_formatter(&tinytemplate::format_unescaped);
Expand Down
File renamed without changes.
21 changes: 0 additions & 21 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,3 @@ pub struct Company {
pub name: String,
pub statement: Fact<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Event {
pub tail_number: String,
pub owner: Fact<Company>,
pub date: String,
pub from_airport: String,
pub to_airport: String,
pub two_way: bool,
pub commercial_emissions_kg: Fact<usize>,
pub emissions_kg: Fact<usize>,
pub source: String,
pub source_date: String,
}

#[derive(Serialize)]
pub struct Context {
pub event: Event,
pub dane_emissions_kg: Fact<usize>,
pub dane_years: String,
}

0 comments on commit 09a4c48

Please sign in to comment.