|
|
@@ -11,6 +11,7 @@ use std::io::BufWriter;
|
|
|
use std::io::BufReader;
|
|
|
use std::fs::File;
|
|
|
use std::{thread, time};
|
|
|
+use std::collections::HashMap;
|
|
|
|
|
|
/// Fucking egun is a mess. It does not even use css and is built using tables. This is an attempt to parse it.
|
|
|
|
|
|
@@ -106,11 +107,13 @@ fn parse_url(url: &str) -> Vec<Auction> {
|
|
|
let mut auctions = vec![];
|
|
|
|
|
|
if let Ok(mut resp) = reqwest::get(url) {
|
|
|
+
|
|
|
if !resp.status().is_success() {
|
|
|
+ println!("ERR {:?}", resp.text());
|
|
|
return auctions;
|
|
|
}
|
|
|
|
|
|
- let text = resp.text().unwrap_or("".to_string());
|
|
|
+ let text = resp.text().unwrap_or("".to_string());
|
|
|
|
|
|
|
|
|
|
|
|
@@ -219,19 +222,29 @@ fn parse_url(url: &str) -> Vec<Auction> {
|
|
|
|
|
|
|
|
|
|
|
|
-fn daemon(queries: Vec<Query>) {
|
|
|
+fn daemon(queries: Vec<Query>, loaded_auctions: Vec<Auction>) {
|
|
|
|
|
|
+ dbg!(&queries);
|
|
|
+ // let _s = loaded_auctions.into_iter().map(|x| (x.url.clone(), x.clone())).collect::<Vec<_>>();
|
|
|
+ let mut auction_map: HashMap<String, Auction> = loaded_auctions.into_iter().map(|x| (x.url.clone(), x.clone())).collect();
|
|
|
|
|
|
println!("Starting daemon with {} active queries", queries.len());
|
|
|
loop {
|
|
|
- let mut auctions = vec![];
|
|
|
+ // TODO: see if we can get rid of clone
|
|
|
+ let auction_map = auction_map.clone();
|
|
|
+ // let mut auctions = vec![];
|
|
|
for mut query in queries.clone() {
|
|
|
query.run();
|
|
|
- auctions.extend(query.auctions);
|
|
|
+ // auctions.extend(query.auctions);
|
|
|
+ for auction in query.auctions {
|
|
|
+ // auction_map.insert(auction.url, auction.clone());
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
- println!("{} auctions found", auctions.len());
|
|
|
+ println!("{} auctions found", &auction_map.len());
|
|
|
let writer = BufWriter::new(File::create("db.json").unwrap());
|
|
|
|
|
|
+ let mut auctions: Vec<Auction> = auction_map.into_iter().map(|(x,y)| y).collect();
|
|
|
auctions.sort_by_key(|k| k.remaining);
|
|
|
|
|
|
serde_json::to_writer_pretty(writer, &auctions).unwrap();
|
|
|
@@ -248,13 +261,19 @@ fn main() {
|
|
|
|
|
|
|
|
|
let reader = BufReader::new(File::open("urls.json").unwrap());
|
|
|
+ // let reader = BufReader::new(File::open("url_local.json").unwrap());
|
|
|
let urls: Vec<String> = serde_json::from_reader(reader).unwrap_or(vec![]);
|
|
|
|
|
|
|
|
|
+ let reader = BufReader::new(File::open("db.json").unwrap());
|
|
|
+ let auctions: Vec<Auction> = serde_json::from_reader(reader).unwrap_or(vec![]);
|
|
|
+
|
|
|
+
|
|
|
daemon(
|
|
|
urls.iter()
|
|
|
.map(|x| Query {url: x.to_string(), ..Default::default()})
|
|
|
- .collect::<Vec<Query>>()
|
|
|
+ .collect::<Vec<Query>>(),
|
|
|
+ auctions
|
|
|
);
|
|
|
|
|
|
}
|