added files
This commit is contained in:
commit
b26022b993
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1013
Cargo.lock
generated
Normal file
1013
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "query-docker-tags"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.127", features = ["derive"] }
|
||||
serde_json = "1.0.66"
|
||||
reqwest = { version = "0.11.4", features = ["blocking", "json"] }
|
||||
chrono = "0.4.19"
|
||||
# crossterm = "0.17"
|
||||
# tui = { version = "0.12", default-features = false, features = ['crossterm'] }
|
4
install-dev-dependencies.sh
Normal file
4
install-dev-dependencies.sh
Normal file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo apt install libssl-dev
|
||||
|
77
src/main.rs
Normal file
77
src/main.rs
Normal file
@ -0,0 +1,77 @@
|
||||
use chrono::DateTime;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Image {
|
||||
architecture: String,
|
||||
os: String,
|
||||
size: i32,
|
||||
last_pulled: String,
|
||||
last_pushed: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Result {
|
||||
images: Vec<Image>,
|
||||
last_updater_username: String,
|
||||
#[serde(rename(deserialize = "name"))]
|
||||
tag_name: String,
|
||||
last_updated: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Tags {
|
||||
count: i32,
|
||||
next_page: Option<String>,
|
||||
prev_page: Option<String>,
|
||||
results: Vec<Result>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//docker hub exposes tags stored in json at the following url
|
||||
//https://hub.docker.com/v2/repositories/rocketchat/rocket.chat/tags
|
||||
|
||||
//TODO fill them dynamic instead of hardcoded
|
||||
let group = "rocketchat";
|
||||
let repo = "rocket.chat";
|
||||
let request = format!(
|
||||
"https://hub.docker.com/v2/repositories/{}/{}/tags",
|
||||
group, repo
|
||||
);
|
||||
|
||||
//get response
|
||||
let res = reqwest::blocking::get(request).unwrap();
|
||||
|
||||
//convert it to json
|
||||
let raw = res.text().unwrap();
|
||||
let tags: Tags = serde_json::from_str(&raw).unwrap();
|
||||
|
||||
let now = chrono::Utc::now();
|
||||
for result in tags.results {
|
||||
let rfc3339 = DateTime::parse_from_rfc3339(&result.last_updated).unwrap();
|
||||
let dif = now - rfc3339.with_timezone(&chrono::Utc);
|
||||
println!("{} vor {}", result.tag_name, format_time_nice(dif));
|
||||
}
|
||||
}
|
||||
|
||||
fn format_time_nice(time: chrono::Duration) -> String {
|
||||
if time.num_weeks() == 52 {
|
||||
format!("{} Jahr", (time.num_weeks() / 52) as i32)
|
||||
} else if time.num_weeks() > 103 {
|
||||
format!("{} Jahren", (time.num_weeks() / 52) as i32)
|
||||
} else if time.num_days() == 1 {
|
||||
format!("{} Tag", time.num_days())
|
||||
} else if time.num_days() > 1 {
|
||||
format!("{} Tagen", time.num_days())
|
||||
} else if time.num_hours() == 1 {
|
||||
format!("{} Stunde", time.num_hours())
|
||||
} else if time.num_hours() > 1 {
|
||||
format!("{} Stunden", time.num_hours())
|
||||
} else if time.num_minutes() == 1 {
|
||||
format!("{} Minute", time.num_minutes())
|
||||
} else if time.num_minutes() > 1 {
|
||||
format!("{} Minuten", time.num_minutes())
|
||||
} else {
|
||||
format!("{} Sekunden", time.num_seconds())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user