|
|
|
@ -1,34 +1,57 @@ |
|
|
|
|
use serde::Deserialize; |
|
|
|
|
use std::{thread, time}; |
|
|
|
|
use serde_json::Value; |
|
|
|
|
use std::collections::HashMap; |
|
|
|
|
use std::env; |
|
|
|
|
|
|
|
|
|
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 INCIDENTS_URL: &str = "https://status.robertsspaceindustries.com/static/content/api/v0/incidents/timeline.en.json"; |
|
|
|
|
|
|
|
|
|
const STATUS_URL: &str = |
|
|
|
|
"https://status.robertsspaceindustries.com/static/content/api/v0/systems.en.json"; |
|
|
|
|
const INCIDENTS_URL: &str = |
|
|
|
|
"https://status.robertsspaceindustries.com/static/content/api/v0/incidents/timeline.en.json"; |
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)] |
|
|
|
|
struct Status { |
|
|
|
|
name: String, |
|
|
|
|
status: String, |
|
|
|
|
order: u8, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)] |
|
|
|
|
struct Incidents { |
|
|
|
|
count: u16, |
|
|
|
|
days: Vec<HashMap<String, String>>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn get_incidents() -> Result<(),reqwest::Error> { |
|
|
|
|
// TODO add parsing for the data this returns
|
|
|
|
|
fn get_incidents() -> Result<(), reqwest::Error> { |
|
|
|
|
let res = reqwest::blocking::get(INCIDENTS_URL)?; |
|
|
|
|
let data = res.text()?; |
|
|
|
|
// let pu = &data[1];
|
|
|
|
|
// let ea = &data[2];
|
|
|
|
|
//println!("Persistent Universe: {}\nEA: {}", pu.status, ea.status);
|
|
|
|
|
dbg!(data); |
|
|
|
|
let data: Value = res.json()?; |
|
|
|
|
let mut day; |
|
|
|
|
for i in 0..5 { |
|
|
|
|
day = &data["days"][i]; |
|
|
|
|
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(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn get_status() -> Result<(),reqwest::Error> { |
|
|
|
|
fn get_status() -> Result<(), reqwest::Error> { |
|
|
|
|
let res = reqwest::blocking::get(STATUS_URL)?; |
|
|
|
|
let data = res.json::<Vec<Status>>()?; |
|
|
|
|
let pu = &data[1]; |
|
|
|
@ -37,13 +60,27 @@ fn get_status() -> Result<(),reqwest::Error> { |
|
|
|
|
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() { |
|
|
|
|
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), |
|
|
|
|
_ => () |
|
|
|
|
_ => (), |
|
|
|
|
}, |
|
|
|
|
_ => help(), |
|
|
|
|
}, |
|
|
|
|
_ => help(), |
|
|
|
|
} |
|
|
|
|
// match get_incidents(){
|
|
|
|
|
// Err(e) => println!("{:?}", e),
|
|
|
|
|
// _ => ()
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|