Johann Woelper 7 роки тому
батько
коміт
35c55ac84f
4 змінених файлів з 28 додано та 171 видалено
  1. 0 142
      db.json
  2. 27 17
      src/main.rs
  3. 1 1
      src/query.rs
  4. 0 11
      urls.json

+ 0 - 142
db.json

@@ -1,142 +0,0 @@
-[
-  {
-    "price": 645.0,
-    "desc": "Remington Model 783 Accuracy",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190630T131100/20190630T131100&text=Remington Model 783 Accuracy&location=&details=",
-    "thumb": "http://egun.de/market/images/picture.gif",
-    "remaining": 257760,
-    "url": "http://egun.de/market/item.php?id=7525551",
-    "timestamp": 1561893087,
-    "is_price_final": true
-  },
-  {
-    "price": 1399.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=20190703T235700/20190703T235700&text=Accuracy International Chassis System (AICS-AX 2.0) FDE Remington 700 SA .308 Repetierbüchsen&location=&details=",
-    "thumb": "http://egun.de/market/images/picture.gif",
-    "remaining": 266880,
-    "url": "http://egun.de/market/item.php?id=7020521",
-    "timestamp": 1562191050,
-    "is_price_final": false
-  },
-  {
-    "price": 46.35,
-    "desc": "MSZU Auktion Harris Zweibein 9\"-13\" 1A2-L",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190614T121700/20190614T121700&text=MSZU Auktion Harris Zweibein 9\"-13\" 1A2-L&location=&details=",
-    "thumb": "http://egun.de/market/images/picture.gif",
-    "remaining": 304440,
-    "url": "http://egun.de/market/item.php?id=7481474",
-    "timestamp": 1560507477,
-    "is_price_final": true
-  },
-  {
-    "price": 655.0,
-    "desc": "LEE-ENFIELD MOD. NO 4 MK I, KAL. .308 WIN.",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190707T215300/20190707T215300&text=LEE-ENFIELD MOD. NO 4 MK I, KAL. .308 WIN.&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/3.7517103.716985898.jpg",
-    "remaining": 605040,
-    "url": "http://egun.de/market/item.php?id=7517103",
-    "timestamp": 1562529212,
-    "is_price_final": false
-  },
-  {
-    "price": 2199.0,
-    "desc": "LuxDefTec M14 Cal. 308 Win inkl. Montage",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190708T110900/20190708T110900&text=LuxDefTec M14 Cal. 308 Win inkl. Montage&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/6.7510941.937973306.jpg",
-    "remaining": 652800,
-    "url": "http://egun.de/market/item.php?id=7510941",
-    "timestamp": 1562576969,
-    "is_price_final": false
-  },
-  {
-    "price": 108.95,
-    "desc": "Harris Zweibein 1A2-LM Höhe 9-13\"/ ca. 23-33cm/ Rastenverstellung/ gummierte Füße",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190709T164800/20190709T164800&text=Harris Zweibein 1A2-LM Höhe 9-13\"/ ca. 23-33cm/ Rastenverstellung/ gummierte Füße&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/5.7474724.408757137.jpg",
-    "remaining": 759540,
-    "url": "http://egun.de/market/item.php?id=7474724",
-    "timestamp": 1562683711,
-    "is_price_final": false
-  },
-  {
-    "price": 650.0,
-    "desc": "Enfield Mod 2A1, Kal..308Win",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190709T212600/20190709T212600&text=Enfield Mod 2A1, Kal..308Win&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/4.7216322.1511970536.jpg",
-    "remaining": 776220,
-    "url": "http://egun.de/market/item.php?id=7216322",
-    "timestamp": 1562700392,
-    "is_price_final": false
-  },
-  {
-    "price": 108.95,
-    "desc": "Harris Zweibein 1A2-L: Höhe 9-13\"/ ca. 23-33cm, stufenlos einstellbar, gummierte Füße",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190622T152500/20190622T152500&text=Harris Zweibein 1A2-L: Höhe 9-13\"/ ca. 23-33cm, stufenlos einstellbar, gummierte Füße&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/2.7081930.306653604.jpg",
-    "remaining": 1006920,
-    "url": "http://egun.de/market/item.php?id=7081930",
-    "timestamp": 1561209957,
-    "is_price_final": true
-  },
-  {
-    "price": 103.0,
-    "desc": "Top Sammlerstück ! Lee Enfield Ishapore 2A1, Kaliber: .308 Winchester",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190712T201400/20190712T201400&text=Top Sammlerstück ! Lee Enfield Ishapore 2A1, Kaliber: .308 Winchester&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/3.7524552.575823640.jpg",
-    "remaining": 1031100,
-    "url": "http://egun.de/market/item.php?id=7524552",
-    "timestamp": 1562955272,
-    "is_price_final": false
-  },
-  {
-    "price": 5649.0,
-    "desc": "Accuracy 308 Win Sniper Custom AICS-AX GREEN Klappschaft Syst Remington 700 L.W. HELICAL BULL Match",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190625T192300/20190625T192300&text=Accuracy 308 Win Sniper Custom AICS-AX GREEN Klappschaft Syst Remington 700 L.W. HELICAL BULL Match&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/0.7495531.1277774880.jpg",
-    "remaining": 1280400,
-    "url": "http://egun.de/market/item.php?id=7495531",
-    "timestamp": 1561483437,
-    "is_price_final": true
-  },
-  {
-    "price": 3249.0,
-    "desc": "@ Accuracy HOWA 1500 Kal. .308 Win Sniper Custom GRS BERSERK Schaft EBI 4-K Bremse ZF Target Master",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190625T193100/20190625T193100&text=@ Accuracy HOWA 1500 Kal. .308 Win Sniper Custom GRS BERSERK Schaft EBI 4-K Bremse ZF Target Master&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/0.7495570.261427846.jpg",
-    "remaining": 1280880,
-    "url": "http://egun.de/market/item.php?id=7495570",
-    "timestamp": 1561483917,
-    "is_price_final": true
-  },
-  {
-    "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=20190716T083500/20190716T083500&text=Sig Arms SHR 970 Magazin, 30/06 ,7x64, 9,3x62 usw. Neu&location=&details=",
-    "thumb": "http://egun.de/market/cache/aucimg/64x64/2.7506617.943962973.jpg",
-    "remaining": 1334760,
-    "url": "http://egun.de/market/item.php?id=7506617",
-    "timestamp": 1563258927,
-    "is_price_final": false
-  },
-  {
-    "price": 630.0,
-    "desc": "B&T GRS Gewehr Schalldämpfer .308 + B&T Kompensator - Accuracy International M18x1,5 Brügger Thomet",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190718T130500/20190718T130500&text=B&T GRS Gewehr Schalldämpfer .308 + B&T Kompensator - Accuracy International M18x1,5 Brügger Thomet&location=&details=",
-    "thumb": "http://egun.de/market/images/picture.gif",
-    "remaining": 1523760,
-    "url": "http://egun.de/market/item.php?id=6884512",
-    "timestamp": 1563447930,
-    "is_price_final": false
-  },
-  {
-    "price": 1495.0,
-    "desc": "Accuracy International AX Chassis System grün",
-    "gcal": "http://www.google.com/calendar/event?action=TEMPLATE&dates=20190728T111700/20190728T111700&text=Accuracy International AX Chassis System grün&location=&details=",
-    "thumb": "http://egun.de/market/images/picture.gif",
-    "remaining": 2381280,
-    "url": "http://egun.de/market/item.php?id=7102212",
-    "timestamp": 1564305450,
-    "is_price_final": false
-  }
-]

+ 27 - 17
src/main.rs

@@ -7,9 +7,10 @@ extern crate rocket;
 extern crate rocket_contrib;
 #[macro_use]
 extern crate lazy_static;
+extern crate serde_json;
 
 use chrono::{DateTime, Duration, Local, Utc};
-use serde_json;
+// use serde_json;
 use std::collections::HashMap;
 use std::fs::File;
 use std::io::BufReader;
@@ -32,37 +33,43 @@ lazy_static! {
 
 fn daemon() {
     loop {
-        dbg!("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());
+        serde_json::to_writer_pretty(writer, &*accounts_unlocked).unwrap();
         drop(accounts_unlocked);
 
+        println!(">>> Done.");
+        let pause = time::Duration::from_secs(30);
+        thread::sleep(pause);
+        // break;
+
+
+
 
-        // let pause = time::Duration::from_secs(30);
-        // thread::sleep(pause);
-        break;
     }
 }
 
 fn main() {
 
-    let mut accounts: HashMap<String, Account> = HashMap::new();
-    let mut acc = Account::default();
-    accounts.insert("test".to_string(), acc);
+    // let mut accounts: HashMap<String, Account> = HashMap::new();
+    // let mut acc = Account::default();
+    // accounts.insert("test".to_string(), acc);
 
-    let mut q = Query::default();
-    let auction = Auction::default();
-    q.auctions.insert("sdsd".to_string(), auction);
+    // let mut q = Query::default();
+    // let auction = Auction::default();
+    // q.auctions.insert("sdsd".to_string(), auction);
 
-    let mut queries: HashMap<String, Query> = HashMap::new();
-    queries.insert("http://bla".to_string(), q);
+    // let mut queries: HashMap<String, Query> = HashMap::new();
+    // queries.insert("http://bla".to_string(), q);
 
-    let j = serde_json::to_string_pretty(&accounts).unwrap();
-    print!("{}", j);
+    // let j = serde_json::to_string_pretty(&accounts).unwrap();
+    // print!("{}", j);
 
     match File::open("accounts.json") {
         Ok(f) => {
@@ -73,8 +80,11 @@ fn main() {
                         let mut accounts_unlocked = ACCOUNTS.lock().unwrap();
                         *accounts_unlocked = accounts;
                     }
-                    // start daemon
-                    daemon();
+                    // start daemon before running web server
+                    thread::spawn(move || {
+                        daemon();
+                    });
+                    // run server
                     server::run();
                 },
                 Err(e) => println!("Parsing account da'a has failed: {:?}", e)

+ 1 - 1
src/query.rs

@@ -116,7 +116,7 @@ fn parse_price(price: &str) -> Option<f32> {
 
 fn auctions_from_url(url: &str) -> HashMap<String, Auction> {
     let mut auctions = HashMap::new();
-    dbg!(&url);
+    // dbg!(&url);
 
     let client = reqwest::Client::builder()
         .timeout(Some(core::time::Duration::from_secs(2)))

+ 0 - 11
urls.json

@@ -1,11 +0,0 @@
-[
-    "http://www.egun.de/market/list_items.php?mode=qry&query=m1a&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=1900&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
-    "http://www.egun.de/market/list_items.php?mode=qry&query=aics&plusdescr=off&wheremode=and&ewb=&status=0&minprice=300&maxprice=2800&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
-    "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=andewb=1&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
-    "http://www.egun.de/market/list_items.php?mode=qry&query=m305&plusdescr=off&wheremode=and&ewb=1&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
-    "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&maxprice=2200&query=m14+luxdef&quick=1",
-    "http://egun.de/market/list_items.php?mode=qry&query=accuracy&plusdescr=off&wheremode=and&ewb=&status=&minprice=300&maxprice=2100&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc",
-    "http://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&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc"
-]