cache scrape results (no logic to update the cache yet)
This commit is contained in:
parent
4aa2aeb1fc
commit
b57ead4a5c
1 changed files with 17 additions and 5 deletions
22
src/main.rs
22
src/main.rs
|
@ -5,12 +5,14 @@ use bayespam::classifier::Classifier;
|
|||
use serde::{Serialize, Deserialize};
|
||||
use std::path::Path;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, BufWriter};
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct RepoId(i64);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct RepoData {
|
||||
name: String,
|
||||
description: Option<String>,
|
||||
|
@ -21,6 +23,7 @@ struct RepoData {
|
|||
struct IssueId(i64);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct IssueData {
|
||||
title: String,
|
||||
body: String,
|
||||
|
@ -31,6 +34,7 @@ struct IssueData {
|
|||
struct UserId(i64);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct UserData {
|
||||
// login: String,
|
||||
email: String,
|
||||
|
@ -284,8 +288,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let db_path = Path::new("classification.json");
|
||||
let mut db = if db_path.is_file() {
|
||||
let file = File::open(db_path)?;
|
||||
let reader = std::io::BufReader::new(file);
|
||||
serde_json::from_reader(reader)?
|
||||
serde_json::from_reader(BufReader::new(file))?
|
||||
} else {
|
||||
Db::new()
|
||||
};
|
||||
|
@ -297,7 +300,17 @@ async fn main() -> anyhow::Result<()> {
|
|||
Auth::Token(&api_token),
|
||||
url::Url::parse("https://git.deuxfleurs.fr")?
|
||||
)?;
|
||||
let data = get_users_data(&forge).await?;
|
||||
|
||||
let data_path = Path::new("data.json");
|
||||
let data = if data_path.is_file() {
|
||||
let file = File::open(data_path)?;
|
||||
serde_json::from_reader(BufReader::new(file))?
|
||||
} else {
|
||||
let data = get_users_data(&forge).await?;
|
||||
let file = File::create(data_path)?;
|
||||
serde_json::to_writer(BufWriter::new(file), &db)?;
|
||||
data
|
||||
};
|
||||
println!("got {} users", data.len());
|
||||
|
||||
for (user_id, user) in data {
|
||||
|
@ -336,8 +349,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
classifier.save(&mut File::create(model_path)?, false)?;
|
||||
|
||||
let file = File::create(db_path)?;
|
||||
let writer = std::io::BufWriter::new(file);
|
||||
serde_json::to_writer(writer, &db)?;
|
||||
serde_json::to_writer(BufWriter::new(file), &db)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue