more usable
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
/bin
|
||||
|
||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -282,6 +282,7 @@ dependencies = [
|
||||
name = "globalenter"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"chrono",
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
||||
@@ -17,3 +17,4 @@ webbrowser = "0.8.7"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
chrono = "0.4.23"
|
||||
bytes = "1.4.0"
|
||||
|
||||
17
Makefile
Normal file
17
Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
NAME = "globalenter"
|
||||
|
||||
build b:
|
||||
@echo "building x86_64 Linux"
|
||||
RUSTFLAGS=-Awarnings cargo build --release --target x86_64-unknown-linux-gnu -q --frozen
|
||||
@echo "building x86_64 Windows"
|
||||
RUSTFLAGS=-Awarnings cargo build --release --target x86_64-pc-windows-gnu -q --frozen
|
||||
mkdir -p bin
|
||||
cp target/x86_64-unknown-linux-gnu/release/$(NAME) bin/$(NAME)
|
||||
chmod +x bin/$(NAME)
|
||||
cp target/x86_64-pc-windows-gnu/release/$(NAME).exe bin/$(NAME).exe
|
||||
chmod +x bin/$(NAME).exe
|
||||
@echo "done"
|
||||
|
||||
clean c:
|
||||
cargo clean
|
||||
rm -rf bin
|
||||
2
build.sh
2
build.sh
@@ -1,2 +0,0 @@
|
||||
cargo build --target x86_64-pc-windows-gnu --release
|
||||
cargo build --release
|
||||
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