mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-21 09:31:19 +02:00
refactor: make everything a little more modular
This commit is contained in:
38
src/state.rs
Normal file
38
src/state.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
// auto-imports
|
||||
use crate::config::Config;
|
||||
|
||||
// std
|
||||
use std::{
|
||||
fs::{read_to_string, write},
|
||||
error::Error,
|
||||
};
|
||||
|
||||
// log
|
||||
use log::debug;
|
||||
|
||||
/// Reads last tweet id from a file
|
||||
pub fn read_state(s: &str) -> Option<u64> {
|
||||
let state = read_to_string(s);
|
||||
|
||||
if let Ok(s) = state {
|
||||
debug!("Last Tweet ID (from file): {}", &s);
|
||||
return s.parse::<u64>().ok();
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// Writes last treated tweet id to a file
|
||||
pub fn write_state(f: &str, s: u64) -> Result<(), std::io::Error> {
|
||||
write(f, format!("{}", s))
|
||||
}
|
||||
|
||||
/*********
|
||||
* Main functions
|
||||
*********/
|
||||
/// Initiates the DB from path
|
||||
pub fn init_db(config: &Config) -> Result<(), Box<dyn Error>> {
|
||||
println!("config.scootaloo.db_path: {}", config.scootaloo.db_path);
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user