v1
This commit is contained in:
60
src/main.rs
Normal file
60
src/main.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use std::process::exit;
|
||||
|
||||
use chrono::{DateTime, Datelike, Local, Timelike};
|
||||
use reqwest;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::time::error::Error;
|
||||
use tokio::time::{sleep, Duration};
|
||||
use webbrowser::open_browser;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Appointment {
|
||||
locationId: u32,
|
||||
startTimestamp: String,
|
||||
endTimestamp: String,
|
||||
active: bool,
|
||||
duration: u32,
|
||||
remoteInd: bool,
|
||||
}
|
||||
|
||||
const TIME: u64 = 3000;
|
||||
// const LOCATION_ID: u32 = 14321;
|
||||
const LOCATION_ID: u32 = 5023;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
loop {
|
||||
look_for_appointments().await;
|
||||
sleep(Duration::from_millis(TIME)).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn look_for_appointments() {
|
||||
let data = get_data().await.unwrap();
|
||||
|
||||
for appointment in data {
|
||||
let time = appointment.startTimestamp + ":00-05:00";
|
||||
let at = DateTime::parse_from_rfc3339(&time).unwrap();
|
||||
|
||||
println!(
|
||||
"Appointment found on {}/{}/{} at {}:{}",
|
||||
at.day(),
|
||||
at.month(),
|
||||
at.year(),
|
||||
at.hour(),
|
||||
at.minute(),
|
||||
);
|
||||
open_browser(webbrowser::Browser::Default, "https://ttp.cbp.dhs.gov/credential/v1/login?app=GOES-prod&lang=en&state=en:IonIgXB4I9qt02S6cgKydMVA9HXHC1vq").unwrap();
|
||||
exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_data() -> Result<Vec<Appointment>, Error> {
|
||||
let res = reqwest::get(format!(
|
||||
"https://ttp.cbp.dhs.gov/schedulerapi/slots?orderBy=soonest&limit=3&locationId={}&minimum=1",
|
||||
LOCATION_ID
|
||||
))
|
||||
.await;
|
||||
let body: Vec<Appointment> = res.unwrap().json().await.unwrap();
|
||||
Ok(body)
|
||||
}
|
||||
Reference in New Issue
Block a user