Johann Woelper 7 tahun lalu
induk
melakukan
8b8c174088
4 mengubah file dengan 27 tambahan dan 19 penghapusan
  1. 18 17
      app.js
  2. 3 0
      index.html
  3. 5 1
      src/main.rs
  4. 1 1
      urls.json

+ 18 - 17
app.js

@@ -15,29 +15,20 @@ function log() {
 }
 
 function get_items() {
-    var xhr = new XMLHttpRequest();
-    xhr.onload = function() {
-        var data = {};
-        try {
-            data = JSON.parse(xhr.responseText);
-        } catch(e){
-            log('could not parse JSON');
-        }
-        app.items = data;
-    };
-    xhr.open('GET', 'db.json', true);
-    try {
-        xhr.send();
-    } catch(e) {
-        log('err', e);
-    }
+    fetch('db.json')
+    .then(function(response) {
+      return response.json();
+    })
+    .then(function(myJson) {
+      app.items = myJson;
+    });
 }
 
 var app = new Vue({
     el: '#app',
     data: {
         title: "egunner",
-        items: {},
+        items: [],
         debug: false
     },
 
@@ -53,6 +44,16 @@ var app = new Vue({
     },
     
     methods: {
+        auctions_by_date: function() {
+            // console.log(this.items);
+            if (this.items.length == 0) {
+                return []
+            }
+            // // return this.items;
+            // return this.items.sort(function(a, b) {
+            //     return a.timestamp < b.timestamp;
+            //   })
+        }
     },
     
     watch: {

+ 3 - 0
index.html

@@ -50,7 +50,10 @@
     
     <div class="content">
       
+      <!-- {{data}} -->
+
       <template v-for="item in items" v-if="item.price != null">
+        {{item.remaining}}
         <div class="panel">
           <div class="grid-auto">
             <div >

+ 5 - 1
src/main.rs

@@ -1,5 +1,6 @@
 #[macro_use]
 extern crate serde_derive;
+use core::cmp::Ordering::Equal;
 use reqwest;
 use chrono::{Utc, Duration, Local, DateTime};
 use select::document::Document;
@@ -221,7 +222,7 @@ fn parse_url(url: &str) -> Vec<Auction> {
 fn daemon(queries: Vec<Query>) {
     
     
-    println!("Starting daemon with {}", queries.len());
+    println!("Starting daemon with {} active queries", queries.len());
     loop {
         let mut auctions = vec![];
         for mut query in queries.clone() {
@@ -230,6 +231,9 @@ fn daemon(queries: Vec<Query>) {
         }
         println!("{} auctions found", auctions.len());
         let writer = BufWriter::new(File::create("db.json").unwrap());
+
+        auctions.sort_by_key(|k| k.remaining);
+
         serde_json::to_writer_pretty(writer, &auctions).unwrap();
         let pause = time::Duration::from_secs(300);
         thread::sleep(pause);

+ 1 - 1
urls.json

@@ -1,6 +1,6 @@
 [
     "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=minprice=200&maxprice=&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=minprice=200&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",