Make the application update every now and then

This commit is contained in:
Savanni D'Gerinel 2023-08-10 09:11:05 -04:00
parent 63884a32f6
commit 6a6dc3dc1e
2 changed files with 24 additions and 13 deletions

View File

@ -94,8 +94,9 @@ pub fn main() {
async move {
let soluna_client = SolunaClient::new();
loop {
let transit = soluna_client
.request(latitude, longitude, Local::now())
.request(latitude.clone(), longitude.clone(), Local::now())
.await;
let now = Local::now();
@ -104,11 +105,11 @@ pub fn main() {
next_event: EVENTS.next_event(now.with_timezone(&Utc)).unwrap(),
transit: Some(transit),
};
loop {
if let Some(ref gtk_tx) = *core.tx.read().unwrap() {
let _ = gtk_tx.send(Message::Refresh(state.clone()));
}
std::thread::sleep(std::time::Duration::from_secs(300));
std::thread::sleep(std::time::Duration::from_secs(60));
}
}
});

View File

@ -1,7 +1,7 @@
// 41.78, -71.41
// https://api.solunar.org/solunar/41.78,-71.41,20211029,-4
use chrono::{DateTime, Duration, NaiveTime, Offset, TimeZone, Utc};
use chrono::{DateTime, Duration, Local, NaiveTime, Offset, TimeZone, Timelike, Utc};
use geo_types::{Latitude, Longitude};
use memorycache::MemoryCache;
use reqwest;
@ -111,7 +111,17 @@ impl SolunaClient {
.and_then(|header| header.to_str().ok())
.and_then(|expiration| DateTime::parse_from_rfc2822(expiration).ok())
.map(|dt_local| DateTime::<Utc>::from(dt_local))
.unwrap_or(Utc::now() + Duration::seconds(3600));
.unwrap_or(
Local::now()
.with_hour(0)
.and_then(|dt| dt.with_minute(0))
.and_then(|dt| dt.with_second(0))
.and_then(|dt| dt.with_nanosecond(0))
.map(|dt| dt.with_timezone(&Utc))
.unwrap()
+ Duration::days(1),
);
println!("expiration: {:?}", expiration);
let soluna: SunMoonJs = response.json().await.unwrap();
(expiration, soluna)
})