mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-22 08:01:47 +03:00
add backup api for globe
This commit is contained in:
parent
85f22776f1
commit
3ac646a708
@ -24,7 +24,7 @@ fn init(_our: Address) {
|
||||
"User-Agent".to_string(),
|
||||
"ipapi.co/#rust-v1.5".to_string(),
|
||||
)])),
|
||||
60,
|
||||
10,
|
||||
vec![],
|
||||
) {
|
||||
Ok(response) => match serde_json::from_slice::<serde_json::Value>(response.body()) {
|
||||
@ -39,8 +39,40 @@ fn init(_our: Address) {
|
||||
println!("Failed to parse location: {e:?}");
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Failed to fetch location: {e:?}");
|
||||
Err(_) => {
|
||||
// try other API
|
||||
match http::client::send_request_await_response(
|
||||
http::Method::GET,
|
||||
url::Url::parse("http://ip-api.com/json/").unwrap(),
|
||||
Some(std::collections::HashMap::from([(
|
||||
"User-Agent".to_string(),
|
||||
"curl/7.54.1".to_string(),
|
||||
)])),
|
||||
10,
|
||||
vec![],
|
||||
) {
|
||||
Ok(response) => {
|
||||
match serde_json::from_slice::<serde_json::Value>(response.body()) {
|
||||
Ok(location) => {
|
||||
if location.get("lat").is_some() && location.get("lon").is_some() {
|
||||
let location_json = serde_json::json!({
|
||||
"latitude": location.get("lat").unwrap(),
|
||||
"longitude": location.get("lon").unwrap(),
|
||||
});
|
||||
break location_json;
|
||||
} else {
|
||||
println!("Failed to parse location: {location:?}");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to parse location: {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to fetch location: {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
|
Loading…
Reference in New Issue
Block a user