mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
add a function to get the timestamp of the last provider-db update
This commit is contained in:
@@ -807,4 +807,6 @@ lazy_static::lazy_static! {
|
|||||||
("narod.ru", &*P_YANDEX_RU),
|
("narod.ru", &*P_YANDEX_RU),
|
||||||
("ziggo.nl", &*P_ZIGGO_NL),
|
("ziggo.nl", &*P_ZIGGO_NL),
|
||||||
].iter().copied().collect();
|
].iter().copied().collect();
|
||||||
|
|
||||||
|
pub static ref PROVIDER_UPDATED: chrono::NaiveDate = chrono::NaiveDate::from_ymd(2020, 9, 19);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ mod data;
|
|||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::dc_tools::EmailAddress;
|
use crate::dc_tools::EmailAddress;
|
||||||
use crate::provider::data::PROVIDER_DATA;
|
use crate::provider::data::{PROVIDER_DATA, PROVIDER_UPDATED};
|
||||||
|
use chrono::{NaiveDateTime, NaiveTime};
|
||||||
|
|
||||||
#[derive(Debug, Display, Copy, Clone, PartialEq, FromPrimitive, ToPrimitive)]
|
#[derive(Debug, Display, Copy, Clone, PartialEq, FromPrimitive, ToPrimitive)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
@@ -91,11 +92,18 @@ pub fn get_provider_info(addr: &str) -> Option<&Provider> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns update timestamp in seconds, UTC, compatible for comparison with time() and database times
|
||||||
|
pub fn get_provider_update_timestamp() -> i64 {
|
||||||
|
NaiveDateTime::new(*PROVIDER_UPDATED, NaiveTime::from_hms(0, 0, 0)).timestamp_millis() / 1_000
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::indexing_slicing)]
|
#![allow(clippy::indexing_slicing)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::dc_tools::time;
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_provider_info_unexistant() {
|
fn test_get_provider_info_unexistant() {
|
||||||
@@ -138,4 +146,16 @@ mod tests {
|
|||||||
let provider = get_provider_info("user@googlemail.com").unwrap();
|
let provider = get_provider_info("user@googlemail.com").unwrap();
|
||||||
assert!(provider.status == Status::PREPARATION);
|
assert!(provider.status == Status::PREPARATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_provider_update_timestamp() {
|
||||||
|
let timestamp_past = NaiveDateTime::new(
|
||||||
|
NaiveDate::from_ymd(2020, 9, 9),
|
||||||
|
NaiveTime::from_hms(0, 0, 0),
|
||||||
|
)
|
||||||
|
.timestamp_millis()
|
||||||
|
/ 1_000;
|
||||||
|
assert!(get_provider_update_timestamp() <= time());
|
||||||
|
assert!(get_provider_update_timestamp() > timestamp_past);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
import datetime
|
||||||
|
|
||||||
out_all = ""
|
out_all = ""
|
||||||
out_domains = ""
|
out_domains = ""
|
||||||
@@ -169,6 +170,12 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
out_all += " pub static ref PROVIDER_DATA: HashMap<&'static str, &'static Provider> = [\n"
|
out_all += " pub static ref PROVIDER_DATA: HashMap<&'static str, &'static Provider> = [\n"
|
||||||
out_all += out_domains;
|
out_all += out_domains;
|
||||||
out_all += " ].iter().copied().collect();\n}"
|
out_all += " ].iter().copied().collect();\n\n"
|
||||||
|
|
||||||
|
now = datetime.datetime.utcnow()
|
||||||
|
out_all += " pub static ref PROVIDER_UPDATED: chrono::NaiveDate = "\
|
||||||
|
"chrono::NaiveDate::from_ymd("+str(now.year)+", "+str(now.month)+", "+str(now.day)+");\n"
|
||||||
|
|
||||||
|
out_all += "}"
|
||||||
|
|
||||||
print(out_all)
|
print(out_all)
|
||||||
|
|||||||
Reference in New Issue
Block a user