more usable
This commit is contained in:
46
src/main.rs
46
src/main.rs
@@ -1,6 +1,7 @@
|
||||
use std::process::exit;
|
||||
use tokio::io::{self, AsyncReadExt};
|
||||
|
||||
use chrono::{DateTime, Datelike, Local, Timelike};
|
||||
use bytes::BytesMut;
|
||||
use chrono::{DateTime, Datelike, Timelike};
|
||||
use reqwest;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::time::error::Error;
|
||||
@@ -18,19 +19,39 @@ struct Appointment {
|
||||
}
|
||||
|
||||
const TIME: u64 = 3000;
|
||||
// const LOCATION_ID: u32 = 14321;
|
||||
const LOCATION_ID: u32 = 5023;
|
||||
const CHARLOTTE: u32 = 14321;
|
||||
// const TESTING: u32 = 5023;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let mut location_id: u32 = CHARLOTTE;
|
||||
let mut buf = [0, 0, 0, 0];
|
||||
|
||||
println!("Enter a location id to override the default (Charlotte, NC): ");
|
||||
let loc_input = io::stdin().read(&mut buf).await;
|
||||
|
||||
if loc_input.unwrap() > 1 {
|
||||
location_id = String::from_utf8(buf.to_vec())
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap();
|
||||
}
|
||||
eprintln!("Using default location (Charlotte, NC): {}", location_id);
|
||||
|
||||
println!("Looking for appointments at location id: {}", location_id);
|
||||
loop {
|
||||
look_for_appointments().await;
|
||||
look_for_appointments(location_id).await;
|
||||
println!(
|
||||
"No appointments found, trying again in {} seconds",
|
||||
TIME / 1000
|
||||
);
|
||||
sleep(Duration::from_millis(TIME)).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn look_for_appointments() {
|
||||
let data = get_data().await.unwrap();
|
||||
async fn look_for_appointments(location_id: u32) {
|
||||
let data = get_data(location_id).await.unwrap();
|
||||
|
||||
for appointment in data {
|
||||
let time = appointment.startTimestamp + ":00-05:00";
|
||||
@@ -45,14 +66,19 @@ async fn look_for_appointments() {
|
||||
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)
|
||||
|
||||
println!("Press any key to continue...");
|
||||
io::stdin()
|
||||
.read_buf(&mut BytesMut::with_capacity(10))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_data() -> Result<Vec<Appointment>, Error> {
|
||||
async fn get_data(location_id: u32) -> 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
|
||||
location_id
|
||||
))
|
||||
.await;
|
||||
let body: Vec<Appointment> = res.unwrap().json().await.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user