Fix territory feed sometimes showing an update twice
This commit is contained in:
parent
19bd9f7328
commit
a0141a3ee2
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1349,7 +1349,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wynnrobot"
|
||||
version = "0.13.0"
|
||||
version = "0.13.1"
|
||||
dependencies = [
|
||||
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"configure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
authors = ["Sakuhl <2012collector@gmail.com>"]
|
||||
name = "wynnrobot"
|
||||
version = "0.13.0"
|
||||
version = "0.13.1"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.0"
|
||||
|
@ -28,12 +28,20 @@ pub fn territory_livefeed() {
|
||||
|
||||
let mut territories: Value = serde_json::from_reader(resp).unwrap();
|
||||
|
||||
let mut timestamp = territories.as_object().unwrap().get("request").unwrap().as_object().unwrap().get("timestamp").unwrap().as_u64().unwrap();
|
||||
|
||||
loop {
|
||||
thread::sleep_ms(10_000); // 10 seconds
|
||||
let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=territoryList").unwrap();
|
||||
|
||||
let new_territories: Value = serde_json::from_reader(resp).unwrap();
|
||||
|
||||
let new_timestamp = new_territories.as_object().unwrap().get("request").unwrap().as_object().unwrap().get("timestamp").unwrap().as_u64().unwrap();
|
||||
if !(new_timestamp > timestamp) { // time went backwards for wynncraft?
|
||||
continue;
|
||||
}
|
||||
timestamp = new_timestamp;
|
||||
|
||||
for key in territories.get("territories").unwrap().as_object().unwrap().keys() {
|
||||
let value = territories.get("territories").unwrap().as_object().unwrap().get(key).unwrap();
|
||||
let new_value = new_territories.get("territories").unwrap().as_object().unwrap().get(key).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user