Browse Source

first proto

Johann Woelper 5 years ago
parent
commit
29ca6f85f4
5 changed files with 212 additions and 22 deletions
  1. 1 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 188 14
      accounts.json
  4. 18 7
      src/main.rs
  5. 4 1
      src/query.rs

+ 1 - 0
Cargo.lock

@@ -450,6 +450,7 @@ dependencies = [
  "serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]

+ 1 - 0
Cargo.toml

@@ -14,6 +14,7 @@ serde_derive = "1.0"
 serde_json = "1.0"
 rocket = "0.4.1"
 lazy_static = "*"
+url = "*"
 
 [dependencies.rocket_contrib]
 version = "0.4.1"

+ 188 - 14
accounts.json

@@ -1,6 +1,185 @@
 {
+  "johann": {
+    "queries": {
+      "http://www.egun.de/market/list_items.php?mode=qry&query=m305&plusdescr=off&wheremode=and&ewb=1": {
+        "auctions": {},
+        "avg_price": null
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&query=308+enfield&plusdescr=off&wheremode=and&ewb=1": {
+        "auctions": {
+          "http://egun.de/market/item.php?id=7545805": {
+            "price": 3.5,
+            "desc": "Seltene Lee Enfield Ishapore 2A1 im Kal. 308 Win",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190728T202400/20190728T202400&text=Seltene+Lee+Enfield+Ishapore+2A1+im+Kal.+308+Win&location=&details=",
+            "thumb": "http://egun.de/market/cache/aucimg/64x64/0.7545805.565137928.jpg",
+            "remaining": 1114080,
+            "url": "http://egun.de/market/item.php?id=7545805",
+            "timestamp": 1564338295,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7550217": {
+            "price": 749.0,
+            "desc": "Rep. - Büchse .308 Win.; Enfield AIA M10 No.4 Mk.IV top Präzision Sniper Einzelstück selten Rarität",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190716T211100/20190716T211100&text=Rep.+-+B%C3%BCchse+.308+Win.%3B+Enfield+AIA+M10+No.4+Mk.IV+top+Pr%C3%A4zision+Sniper+Einzelst%C3%BCck+selten+Rarit%C3%A4t&location=&details=",
+            "thumb": "http://egun.de/market/cache/aucimg/64x64/4.7550217.1231953745.jpg",
+            "remaining": 80100,
+            "url": "http://egun.de/market/item.php?id=7550217",
+            "timestamp": 1563304315,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7547250": {
+            "price": 376.0,
+            "desc": "Original Enfield No4 Conversion auf 7.62×51mm NATO/ 308 Große Bilder",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190802T221300/20190802T221300&text=Original+Enfield+No4+Conversion+auf+7.62%C3%9751mm+NATO%2F+308+Gro%C3%9Fe+Bilder&location=&details=",
+            "thumb": "http://egun.de/market/images/picture.gif",
+            "remaining": 1552620,
+            "url": "http://egun.de/market/item.php?id=7547250",
+            "timestamp": 1564776835,
+            "is_price_final": false
+          }
+        },
+        "avg_price": 376.16666
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&query=mcmillan&minprice=200": {
+        "auctions": {
+          "http://egun.de/market/item.php?id=7550948": {
+            "price": 525.0,
+            "desc": "McMillan \" Custom \" Repetierer im Kal .308 Winchester",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190811T201400/20190811T201400&text=McMillan+%22+Custom+%22+Repetierer+im+Kal+.308+Winchester&location=&details=",
+            "thumb": "http://egun.de/market/cache/aucimg/64x64/5.7550948.311856634.jpg",
+            "remaining": 2323080,
+            "url": "http://egun.de/market/item.php?id=7550948",
+            "timestamp": 1565547294,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7552914": {
+            "price": 240.0,
+            "desc": "Grayboe Schaft für Remington 700, .308Win, Nachbau McMillan A5",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190728T170700/20190728T170700&text=Grayboe+Schaft+f%C3%BCr+Remington+700%2C+.308Win%2C+Nachbau+McMillan+A5&location=&details=",
+            "thumb": "http://egun.de/market/images/picture.gif",
+            "remaining": 1102260,
+            "url": "http://egun.de/market/item.php?id=7552914",
+            "timestamp": 1564326474,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7348238": {
+            "price": 1579.0,
+            "desc": "Browning X-Bolt /McMillan Kal. 308 Win. - Waffen Outlet",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190716T130900/20190716T130900&text=Browning+X-Bolt+%2FMcMillan+Kal.+308+Win.+-+Waffen+Outlet&location=&details=",
+            "thumb": "http://egun.de/market/cache/aucimg/64x64/4.7348238.481318013.jpg",
+            "remaining": 51180,
+            "url": "http://egun.de/market/item.php?id=7348238",
+            "timestamp": 1563275394,
+            "is_price_final": false
+          }
+        },
+        "avg_price": 781.3333
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&query=accuracy&plusdescr=off&wheremode=and&ewb=&status=&minprice=300&maxprice=2100": {
+        "auctions": {
+          "http://egun.de/market/item.php?id=7525551": {
+            "price": 645.0,
+            "desc": "Remington Model 783 Accuracy",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190722T075900/20190722T075900&text=Remington+Model+783+Accuracy&location=&details=",
+            "thumb": "http://egun.de/market/images/picture.gif",
+            "remaining": 550980,
+            "url": "http://egun.de/market/item.php?id=7525551",
+            "timestamp": 1563775195,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7102212": {
+            "price": 1495.0,
+            "desc": "Accuracy International AX Chassis System grün",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190728T111800/20190728T111800&text=Accuracy+International+AX+Chassis+System+gr%C3%BCn&location=&details=",
+            "thumb": "http://egun.de/market/images/picture.gif",
+            "remaining": 1081320,
+            "url": "http://egun.de/market/item.php?id=7102212",
+            "timestamp": 1564305535,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7547554": {
+            "price": 1699.0,
+            "desc": "Remington 700 Police .308Win. 66cm Lauf, AICS/Accuracy International Klappschaft, EBIARMS-Bremse",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190808T131600/20190808T131600&text=Remington+700+Police+.308Win.+66cm+Lauf%2C+AICS%2FAccuracy+International+Klappschaft%2C+EBIARMS-Bremse&location=&details=",
+            "thumb": "http://egun.de/market/images/picture.gif",
+            "remaining": 2038800,
+            "url": "http://egun.de/market/item.php?id=7547554",
+            "timestamp": 1565263015,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7020521": {
+            "price": 1392.0,
+            "desc": "Accuracy International Chassis System (AICS-AX 2.0) FDE Remington 700 SA .308 Repetierbüchsen",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190806T035100/20190806T035100&text=Accuracy+International+Chassis+System+%28AICS-AX+2.0%29+FDE+Remington+700+SA+.308+Repetierb%C3%BCchsen&location=&details=",
+            "thumb": "http://egun.de/market/images/picture.gif",
+            "remaining": 1832100,
+            "url": "http://egun.de/market/item.php?id=7020521",
+            "timestamp": 1565056315,
+            "is_price_final": false
+          }
+        },
+        "avg_price": 1307.75
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=shr+970&quick=1": {
+        "auctions": {
+          "http://egun.de/market/item.php?id=7506617": {
+            "price": 149.0,
+            "desc": "Sig Arms SHR 970 Magazin, 30/06 ,7x64, 9,3x62 usw. Neu",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190716T083400/20190716T083400&text=Sig+Arms+SHR+970+Magazin%2C+30%2F06+%2C7x64%2C+9%2C3x62+usw.+Neu&location=&details=",
+            "thumb": "http://egun.de/market/cache/aucimg/64x64/2.7506617.943962973.jpg",
+            "remaining": 34680,
+            "url": "http://egun.de/market/item.php?id=7506617",
+            "timestamp": 1563258896,
+            "is_price_final": false
+          }
+        },
+        "avg_price": 149.0
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&maxprice=2200&query=m14+luxdef&quick=1": {
+        "auctions": {},
+        "avg_price": null
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&query=smith+wesson+r8&plusdescr=off&wheremode=and&ewb=1": {
+        "auctions": {},
+        "avg_price": null
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&query=aics&plusdescr=off&wheremode=and&ewb=&status=0&minprice=300&maxprice=2800": {
+        "auctions": {
+          "http://egun.de/market/item.php?id=7552935": {
+            "price": 333.0,
+            "desc": "Tikka T3 Schichtholzschaft / AICS Magazin",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190804T171200/20190804T171200&text=Tikka+T3+Schichtholzschaft+%2F+AICS+Magazin&location=&details=",
+            "thumb": "http://egun.de/market/cache/aucimg/64x64/0.7552935.884702445.jpg",
+            "remaining": 1707360,
+            "url": "http://egun.de/market/item.php?id=7552935",
+            "timestamp": 1564931575,
+            "is_price_final": false
+          },
+          "http://egun.de/market/item.php?id=7020521": {
+            "price": 1392.0,
+            "desc": "Accuracy International Chassis System (AICS-AX 2.0) FDE Remington 700 SA .308 Repetierbüchsen",
+            "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190806T035100/20190806T035100&text=Accuracy+International+Chassis+System+%28AICS-AX+2.0%29+FDE+Remington+700+SA+.308+Repetierb%C3%BCchsen&location=&details=",
+            "thumb": "http://egun.de/market/images/picture.gif",
+            "remaining": 1832100,
+            "url": "http://egun.de/market/item.php?id=7020521",
+            "timestamp": 1565056315,
+            "is_price_final": false
+          }
+        },
+        "avg_price": 862.5
+      },
+      "http://www.egun.de/market/list_items.php?mode=qry&query=m1a&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=1900": {
+        "auctions": {},
+        "avg_price": null
+      }
+    }
+  },
   "offline": {
     "queries": {
+      "http://localhost:8001": {
+        "auctions": {},
+        "avg_price": null
+      },
       "http://localhost:8002": {
         "auctions": {
           "http://egun.de/market/http://egun.de/market/item.php?id=888888": {
@@ -11,24 +190,19 @@
             "remaining": 789000,
             "url": "http://egun.de/market/http://egun.de/market/item.php?id=88888888",
             "timestamp": 1562264532,
-            "is_price_final": false
+            "is_price_final": true
           }
-        }
-      },
-      "http://localhost:8001": {}
+        },
+        "avg_price": 88.88
+      }
     }
   },
-  "johann": {
+  "test": {
     "queries": {
-      "http://www.egun.de/market/list_items.php?mode=qry&query=m1a&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=1900": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&query=aics&plusdescr=off&wheremode=and&ewb=&status=0&minprice=300&maxprice=2800": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=shr+970&quick=1": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&query=smith+wesson+r8&plusdescr=off&wheremode=and&ewb=1": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&query=m305&plusdescr=off&wheremode=and&ewb=1": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&maxprice=2200&query=m14+luxdef&quick=1": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&query=accuracy&plusdescr=off&wheremode=and&ewb=&status=&minprice=300&maxprice=2100": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=harris+1A2-L&quick=1": {},
-      "http://www.egun.de/market/list_items.php?mode=qry&query=308+enfield&plusdescr=off&wheremode=and&ewb=1": {}
+      "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&query=schusssichere+weste": {
+        "auctions": {},
+        "avg_price": null
+      }
     }
   }
 }

+ 18 - 7
src/main.rs

@@ -23,6 +23,10 @@ mod query;
 use query::*;
 mod server;
 use server::run;
+const DBFILE: &str = "accounts.json";
+
+
+
 
 lazy_static! {
     // static ref ACCOUNTS: Mutex<HashMap<String, Account>> = Mutex::new(HashMap::new());
@@ -34,13 +38,19 @@ lazy_static! {
 fn daemon() {
     loop {
         println!(">>> Running update...");
-        let mut accounts_unlocked = ACCOUNTS.lock().unwrap();
 
-        // dbg!(&temp_accounts);
-        for (account_name, account) in accounts_unlocked.clone() {
-            accounts_unlocked.insert(account_name.to_string(), account.updated());
-        }
-        let writer = BufWriter::new(File::create("test.json").unwrap());
+            let accounts_unlocked = ACCOUNTS.lock().unwrap().clone();
+
+            for (account_name, account) in accounts_unlocked {
+                thread::spawn(move || {
+                    let mut accounts = ACCOUNTS.lock().unwrap();
+                    accounts.insert(account_name.to_string(), account.updated());
+                });
+            }
+
+
+        let accounts_unlocked = ACCOUNTS.lock().unwrap();
+        let writer = BufWriter::new(File::create(DBFILE).unwrap());
         serde_json::to_writer_pretty(writer, &*accounts_unlocked).unwrap();
         drop(accounts_unlocked);
 
@@ -57,6 +67,7 @@ fn daemon() {
 
 fn main() {
 
+
     // let mut accounts: HashMap<String, Account> = HashMap::new();
     // let mut acc = Account::default();
     // accounts.insert("test".to_string(), acc);
@@ -71,7 +82,7 @@ fn main() {
     // let j = serde_json::to_string_pretty(&accounts).unwrap();
     // print!("{}", j);
 
-    match File::open("accounts.json") {
+    match File::open(DBFILE) {
         Ok(f) => {
             match serde_json::from_reader::<_, HashMap<String, Account>>(BufReader::new(f)) {
                 Ok(accounts) => {

+ 4 - 1
src/query.rs

@@ -4,6 +4,8 @@ use reqwest;
 use select::document::Document;
 use select::predicate::Name;
 use std::collections::HashMap;
+// extern crate url;
+use url::form_urlencoded::{byte_serialize};
 
 #[derive(Serialize, Deserialize, Debug, Default, Clone)]
 pub struct Auction {
@@ -228,7 +230,8 @@ fn auctions_from_url(url: &str) -> HashMap<String, Auction> {
                         // dbg!(&t_remaining.children());
 
                         let end_date = Utc::now().with_timezone(&Local) + remaining;
-                        auction.gcal = format!("http://www.google.com/calendar/event?action=TEMPLATE&dates={}&text={}&location=&details=", date_to_gcal(end_date), auction.desc);
+                        let urlencoded: String = byte_serialize(auction.desc.as_bytes()).collect();
+                        auction.gcal = format!("http://www.google.com/calendar/event?action=TEMPLATE&dates={}&text={}&location=&details=", date_to_gcal(end_date), urlencoded);
                         auction.remaining = remaining.num_seconds();
                         auction.timestamp = end_date.timestamp();
                         // println!("ENDS\t{:?}", date_to_gcal(remaining));