|
|
@ -1,34 +1,57 @@ |
|
|
|
use serde::Deserialize; |
|
|
|
use serde::Deserialize; |
|
|
|
use std::{thread, time}; |
|
|
|
use serde_json::Value; |
|
|
|
|
|
|
|
use std::collections::HashMap; |
|
|
|
|
|
|
|
use std::env; |
|
|
|
|
|
|
|
|
|
|
|
extern crate reqwest; |
|
|
|
extern crate reqwest; |
|
|
|
|
|
|
|
|
|
|
|
const API_URL: &str = "https://status.robertsspaceindustries.com/"; |
|
|
|
const STATUS_URL: &str = |
|
|
|
|
|
|
|
"https://status.robertsspaceindustries.com/static/content/api/v0/systems.en.json"; |
|
|
|
const STATUS_URL: &str = "https://status.robertsspaceindustries.com/static/content/api/v0/systems.en.json"; |
|
|
|
const INCIDENTS_URL: &str = |
|
|
|
const INCIDENTS_URL: &str = "https://status.robertsspaceindustries.com/static/content/api/v0/incidents/timeline.en.json"; |
|
|
|
"https://status.robertsspaceindustries.com/static/content/api/v0/incidents/timeline.en.json"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)] |
|
|
|
#[derive(Deserialize, Debug)] |
|
|
|
struct Status { |
|
|
|
struct Status { |
|
|
|
name: String, |
|
|
|
name: String, |
|
|
|
status: String, |
|
|
|
status: String, |
|
|
|
order: u8, |
|
|
|
order: u8, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)] |
|
|
|
|
|
|
|
struct Incidents { |
|
|
|
|
|
|
|
count: u16, |
|
|
|
|
|
|
|
days: Vec<HashMap<String, String>>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_incidents() -> Result<(),reqwest::Error> { |
|
|
|
fn get_incidents() -> Result<(), reqwest::Error> { |
|
|
|
// TODO add parsing for the data this returns
|
|
|
|
|
|
|
|
let res = reqwest::blocking::get(INCIDENTS_URL)?; |
|
|
|
let res = reqwest::blocking::get(INCIDENTS_URL)?; |
|
|
|
let data = res.text()?; |
|
|
|
let data: Value = res.json()?; |
|
|
|
// let pu = &data[1];
|
|
|
|
let mut day; |
|
|
|
// let ea = &data[2];
|
|
|
|
for i in 0..5 { |
|
|
|
//println!("Persistent Universe: {}\nEA: {}", pu.status, ea.status);
|
|
|
|
day = &data["days"][i]; |
|
|
|
dbg!(data); |
|
|
|
let date = day["date"] |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
|
|
|
|
.split("T") |
|
|
|
|
|
|
|
.collect::<Vec<&str>>()[0]; |
|
|
|
|
|
|
|
let incidents = day["incidents"].as_array(); |
|
|
|
|
|
|
|
println!("Date: {}", date); |
|
|
|
|
|
|
|
println!("Number of incidents: {}", day["count"]); |
|
|
|
|
|
|
|
for incident in incidents { |
|
|
|
|
|
|
|
for inc in incident { |
|
|
|
|
|
|
|
println!("Title: {}", inc["title"]); |
|
|
|
|
|
|
|
println!("Severity: {}", inc["severity"]); |
|
|
|
|
|
|
|
println!("Resolved: {}", inc["resolved"]); |
|
|
|
|
|
|
|
println!("Content: {}\n", inc["content"]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
println!("\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_status() -> Result<(),reqwest::Error> { |
|
|
|
fn get_status() -> Result<(), reqwest::Error> { |
|
|
|
let res = reqwest::blocking::get(STATUS_URL)?; |
|
|
|
let res = reqwest::blocking::get(STATUS_URL)?; |
|
|
|
let data = res.json::<Vec<Status>>()?; |
|
|
|
let data = res.json::<Vec<Status>>()?; |
|
|
|
let pu = &data[1]; |
|
|
|
let pu = &data[1]; |
|
|
@ -37,13 +60,27 @@ fn get_status() -> Result<(),reqwest::Error> { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn help() { |
|
|
|
|
|
|
|
println!( |
|
|
|
|
|
|
|
"sc_status conveniently checks the Star Citizen Status API.\n\ |
|
|
|
|
|
|
|
Call with '-i' to get detailed information about incidents" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
match get_status(){ |
|
|
|
let args: Vec<String> = env::args().collect(); |
|
|
|
|
|
|
|
match args.len() { |
|
|
|
|
|
|
|
1 => match get_status() { |
|
|
|
|
|
|
|
Err(e) => println!("{:?}", e), |
|
|
|
|
|
|
|
_ => (), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
2 => match args[1].as_ref() { |
|
|
|
|
|
|
|
"-i" => match get_incidents() { |
|
|
|
Err(e) => println!("{:?}", e), |
|
|
|
Err(e) => println!("{:?}", e), |
|
|
|
_ => () |
|
|
|
_ => (), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
_ => help(), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
_ => help(), |
|
|
|
} |
|
|
|
} |
|
|
|
// match get_incidents(){
|
|
|
|
|
|
|
|
// Err(e) => println!("{:?}", e),
|
|
|
|
|
|
|
|
// _ => ()
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|