mirror of
https://codeberg.org/icewind/log-archiver.git
synced 2026-06-03 17:44:06 +02:00
initial stuff
This commit is contained in:
parent
8a1b642ca8
commit
59d087f68f
5 changed files with 1421 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
.env
|
||||||
1355
Cargo.lock
generated
Normal file
1355
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -4,6 +4,11 @@ version = "0.1.0"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
sqlx = { version = "0.3.2", default_features = false, features = ["macros", "postgres", "json", "runtime-tokio"] }
|
||||||
|
dotenv = "0.15.0"
|
||||||
|
main_error = "0.1.0"
|
||||||
|
tokio = { version = "0.2.13", features = ["macros", "time"] }
|
||||||
|
reqwest = { version = "0.10.4", features = [] }
|
||||||
|
serde = "1.0"
|
||||||
|
serde_json = "1.0"
|
||||||
8
schema.sql
Normal file
8
schema.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
CREATE TABLE logs_raw (
|
||||||
|
id INTEGER NOT NULL,
|
||||||
|
json JSONB NOT NULL,
|
||||||
|
time TIMESTAMP WITHOUT TIME ZONE NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE ONLY logs_raw
|
||||||
|
ALTER COLUMN time SET DEFAULT now();
|
||||||
52
src/main.rs
52
src/main.rs
|
|
@ -1,3 +1,51 @@
|
||||||
fn main() {
|
use main_error::MainError;
|
||||||
println!("Hello, world!");
|
use reqwest::Response;
|
||||||
|
use serde_json::Value;
|
||||||
|
use sqlx::postgres::PgPool;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::delay_for;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), MainError> {
|
||||||
|
let pool = PgPool::builder()
|
||||||
|
.max_size(2)
|
||||||
|
.build(&dotenv::var("DATABASE_URL")?)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
|
let row = sqlx::query!("SELECT MAX(id) AS last_archived FROM logs_raw")
|
||||||
|
.fetch_one(&pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let last_demo = 2510323; // TODO dynamically determine this
|
||||||
|
|
||||||
|
let mut last_archived = row.last_archived.unwrap_or_default();
|
||||||
|
|
||||||
|
while last_archived <= last_demo {
|
||||||
|
last_archived += 1;
|
||||||
|
|
||||||
|
println!("{}", last_archived);
|
||||||
|
|
||||||
|
delay_for(Duration::from_millis(200)).await;
|
||||||
|
|
||||||
|
let response: Response = client
|
||||||
|
.get(&format!(
|
||||||
|
"https://logstf.vrchat.network/api/v1/log/{}",
|
||||||
|
last_archived
|
||||||
|
))
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
let body: Value = serde_json::from_str(&response.text().await?)?;
|
||||||
|
|
||||||
|
sqlx::query!(
|
||||||
|
"INSERT INTO logs_raw(id, json) VALUES($1, $2)",
|
||||||
|
last_archived,
|
||||||
|
body
|
||||||
|
)
|
||||||
|
.execute(&pool)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue