Johann Woelper 4 yıl önce
ebeveyn
işleme
2e68b42b9d
7 değiştirilmiş dosya ile 743 ekleme ve 740 silme
  1. 2 2
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 718 718
      accounts.json
  4. BIN
      guntrader
  5. 14 9
      src/main.rs
  6. 2 4
      src/query.rs
  7. 6 6
      src/server.rs

+ 2 - 2
Cargo.lock

@@ -331,7 +331,7 @@ dependencies = [
 
 [[package]]
 name = "guntrader"
-version = "0.2.1"
+version = "0.3.1"
 dependencies = [
  "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -345,7 +345,7 @@ dependencies = [
  "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
- "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "urldecode 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "guntrader"
-version = "0.2.1"
+version = "0.3.1"
 authors = ["Johann Woelper <woelper@gmail.com>"]
 edition = "2018"
 default-run = "guntrader"

Dosya farkı çok büyük olduğundan ihmal edildi
+ 718 - 718
accounts.json


BIN
guntrader


+ 14 - 9
src/main.rs

@@ -3,7 +3,7 @@
 extern crate serde_derive;
 #[macro_use]
 extern crate rocket;
-#[macro_use]
+// #[macro_use]
 extern crate rocket_contrib;
 #[macro_use]
 extern crate lazy_static;
@@ -31,9 +31,9 @@ lazy_static! {
 }
 
 
-fn daemon() {
+fn daemon(interval: u64) {
     loop {
-        info!(">>> UPD");
+        debug!(">>> UPD");
 
         let accounts_unlocked = ACCOUNTS.lock().unwrap();
         let accounts_cl = accounts_unlocked.clone();
@@ -50,7 +50,7 @@ fn daemon() {
         for (account_name, account) in accounts_cl {
             let client = client.clone();
             let t = thread::spawn(move || {
-                info!("ACCT {}", account_name);
+                debug!("ACCT {}", account_name);
                 
                 let updated_account = account.updated(&client);
                 let mut accounts = ACCOUNTS.lock().unwrap();
@@ -71,8 +71,8 @@ fn daemon() {
         serde_json::to_writer_pretty(writer, &*accounts_unlocked).unwrap();
         drop(accounts_unlocked);
 
-        info!("<<< Cycle over, sleeping 30 secs.");
-        let pause = time::Duration::from_secs(30);
+        info!("Waiting {} secs for next update", interval);
+        let pause = time::Duration::from_secs(interval);
         thread::sleep(pause);
 
     }
@@ -88,20 +88,25 @@ fn main() {
             match serde_json::from_reader::<_, HashMap<String, Account>>(BufReader::new(f)) {
                 Ok(accounts) => {
                     {
+                        info!("ACCOUNT DATA LOADED");
                         // Lock once, shove loaded ccounts in
                         let mut accounts_unlocked = ACCOUNTS.lock().unwrap();
                         *accounts_unlocked = accounts;
                     }
+                    info!("START DAEMON");
+
                     // start daemon before running web server
+                    info!("START WEBSERVER");
+
                     thread::spawn(move || {
-                        daemon();
+                        daemon(200);
                     });
                     // run server
                     server::run();
                 },
-                Err(e) => println!("Parsing account da'a has failed: {:?}", e)
+                Err(e) => error!("Parsing account da'a has failed: {:?}", e)
             }
         }
-        Err(e) => println!("Opening accounts file failed. {:?}", e),
+        Err(e) => error!("Opening accounts file failed. {:?}", e),
     }
 }

+ 2 - 4
src/query.rs

@@ -10,7 +10,6 @@ use std::collections::HashMap;
 use url::form_urlencoded::{byte_serialize};
 use log::*;
 
-const MAXCLIENTS: usize = 8;
 
 #[derive(Serialize, Deserialize, Debug, Default, Clone)]
 pub struct Auction {
@@ -32,7 +31,6 @@ impl Auction {
 
 
         // println!("now: {:?} auction: {:?}", Utc::now().with_timezone(&Local).timestamp(), self.timestamp);
-        let was_not_final = self.is_price_final;
         self.is_price_final = Utc::now().with_timezone(&Local).timestamp() > self.timestamp;
         // self.price = price_from_auction(&self.url)
         // TODO: delete ^^ and enable lines below
@@ -163,7 +161,7 @@ fn auction_details(auction: &Auction, client: &Client) -> Auction {
 
 
     match client.get(&auction.url).send() {
-        Ok(mut resp) => {
+        Ok(resp) => {
             // if !resp.status().is_success() {
             //     println!("ERR {:?}", &resp.text());
             // }
@@ -221,7 +219,7 @@ fn auctions_from_url(url: &str, client: &Client) -> HashMap<String, Auction> {
  
 
     match client.get(url).send() {
-        Ok(mut resp) => {
+        Ok(resp) => {
             if !resp.status().is_success() {
                 // println!("ERR {:?}", resp.text_with_charset("windows-1252"));
                 

+ 6 - 6
src/server.rs

@@ -1,8 +1,8 @@
 use rocket_contrib::serve::StaticFiles;
 use rocket_contrib::json::Json;
 use rocket::response::content;
-use rocket::http::ContentType;
-use rocket::response::Response;
+// use rocket::http::ContentType;
+// use rocket::response::Response;
 use std::sync::Mutex;
 use std::collections::HashMap;
 use super::ACCOUNTS;
@@ -28,11 +28,11 @@ pub fn proxy(url: &str) -> Vec<u8> {
             let mut buf: Vec<u8> = vec![];
             match resp.copy_to(&mut buf) {
                 Ok(_r) => buf,
-                Err(e) => vec![]
+                Err(_e) => vec![]
             }
 
         }
-        Err(e) => vec![]
+        Err(_e) => vec![]
     }
 
 }
@@ -40,8 +40,8 @@ pub fn proxy(url: &str) -> Vec<u8> {
 
 #[get("/proxy/<url>")]
 fn proxy_gate(url: String)  -> Vec<u8>{
-    let html = ContentType::parse_flexible("image/jpeg").unwrap();
-    let response = Response::build().header(html).finalize();
+    // let html = ContentType::parse_flexible("image/jpeg").unwrap();
+    // let response = Response::build().header(html).finalize();
     proxy(&urldecode::decode(url))
 }