Add ItemAppearances to track price and page history
All checks were successful
Cargo Build & Test / Rust project - latest (1.88) (push) Successful in 3m30s
Cargo Build & Test / Rust project - latest (1.87) (push) Successful in 3m57s
Cargo Build & Test / Rust project - latest (1.85.1) (push) Successful in 4m9s
Cargo Build & Test / Rust project - latest (1.86) (push) Successful in 9m50s
All checks were successful
Cargo Build & Test / Rust project - latest (1.88) (push) Successful in 3m30s
Cargo Build & Test / Rust project - latest (1.87) (push) Successful in 3m57s
Cargo Build & Test / Rust project - latest (1.85.1) (push) Successful in 4m9s
Cargo Build & Test / Rust project - latest (1.86) (push) Successful in 9m50s
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -1,6 +1,9 @@
|
||||
use actix_web::{App, HttpServer, Responder, Result, get, post, web, web::Data};
|
||||
use chrono::DateTime;
|
||||
use clap::Parser;
|
||||
use ebay_scraper_rust::db::{Listing, ParsedPage, ParsedStorage, SearchURL, get_initialized};
|
||||
use ebay_scraper_rust::db::{
|
||||
ItemAppearances, Listing, ParsedPage, ParsedStorage, SearchURL, get_initialized,
|
||||
};
|
||||
use ebay_scraper_rust::{parser_ebay, parser_storage};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Mutex;
|
||||
@@ -27,6 +30,19 @@ async fn page_get(
|
||||
)))
|
||||
}
|
||||
|
||||
#[get("/listing/{id}/history")]
|
||||
async fn listing_history_get(
|
||||
db: Data<Mutex<rusqlite::Connection>>,
|
||||
id: web::Path<i64>,
|
||||
) -> Result<impl Responder> {
|
||||
let history: Vec<_> = ItemAppearances::lookup(&db.lock().unwrap(), *id)
|
||||
.iter()
|
||||
.inspect(|e| info!("got: {:?}", e))
|
||||
.filter_map(|e| Some((e.timestamp, e.current_bid_usd_cents?)))
|
||||
.collect();
|
||||
Ok(web::Json(history))
|
||||
}
|
||||
|
||||
#[get("/listing/{id}")]
|
||||
async fn listing_get(
|
||||
db: Data<Mutex<rusqlite::Connection>>,
|
||||
@@ -42,7 +58,7 @@ async fn listing_since_get(
|
||||
) -> Result<impl Responder> {
|
||||
Ok(web::Json(Listing::lookup_since(
|
||||
&db.lock().unwrap(),
|
||||
req.0,
|
||||
DateTime::from_timestamp(req.0, 0).unwrap(),
|
||||
req.1,
|
||||
)))
|
||||
}
|
||||
@@ -147,13 +163,15 @@ async fn parse_post(
|
||||
parser_ebay::extract_data_from_html(
|
||||
&std::fs::read_to_string(dir.join(format!("{t}.html"))).unwrap(),
|
||||
×tamp,
|
||||
&category,
|
||||
)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.for_each(|l| {
|
||||
.for_each(|lp| {
|
||||
cnt = cnt + 1;
|
||||
l.add_or_update(&db.lock().unwrap());
|
||||
info!("Inserting id:{}, title:{}", l.item_id, l.title);
|
||||
lp.0.add_or_update(&db.lock().unwrap());
|
||||
lp.1.add_or_update(&db.lock().unwrap());
|
||||
info!("Inserting id:{}, title:{}", lp.0.item_id, lp.0.title);
|
||||
});
|
||||
cnt
|
||||
})
|
||||
@@ -178,6 +196,7 @@ async fn main() -> std::io::Result<()> {
|
||||
App::new()
|
||||
.service(page_get)
|
||||
.service(listing_get)
|
||||
.service(listing_history_get)
|
||||
.service(listing_since_get)
|
||||
.service(parse_post)
|
||||
.service(parse_listings)
|
||||
|
Reference in New Issue
Block a user