ソースを参照

more web stuff and url

Johann Woelper 7 年 前
コミット
2ea4bad349
3 ファイル変更167 行追加13 行削除
  1. 60 0
      app.js
  2. 24 13
      src/main.rs
  3. 83 0
      test.html

+ 60 - 0
app.js

@@ -0,0 +1,60 @@
+Number.prototype.currency = function() { return '$' + this.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') };
+
+
+function log() {
+    console.log('LOG >>>', arguments);
+}
+
+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);
+    }
+}
+
+var app = new Vue({
+    el: '#app',
+    data: {
+        title: "egunner",
+        items: {},
+        debug: false
+    },
+
+    mounted: function () {
+        // hide splash
+        var splash = document.getElementById("splash");
+        splash.style.display = "none";
+        
+        // unhide main container after mount
+        this.$el.style.display = "block";
+    },
+    computed: {
+    },
+    
+    methods: {
+    },
+    
+    watch: {
+    },
+    
+});
+
+
+get_items();
+
+window.setInterval(function(){
+    console.log('refresh');
+    get_items();
+}, 5000);

+ 24 - 13
src/main.rs

@@ -27,18 +27,6 @@ struct Auction {
 }
 
 
-
-fn main() {
-    // let url = "http://www.egun.de/market/list_items.php?mode=qry&query=g36&plusdescr=off&plusdescr=on&wheremode=and&ewb=1&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc";
-    let url = "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=sniper&quick=1";
-    
-    // dbg!(parse_url(url));
-
-    // write out the file
-    let writer = BufWriter::new(File::create("db.json").unwrap());
-    serde_json::to_writer_pretty(writer, &parse_url(url)).unwrap();
-}
-
 fn date_to_gcal(date: DateTime<Local>) -> String {
     format!("{}",
         date.format("%Y%m%dT%H%M00/%Y%m%dT%H%M00")
@@ -115,6 +103,19 @@ fn parse_url(url: &str) -> Vec<Auction> {
                         // println!("PRICE\t{:?}", prices);
                     }
                 
+                    if let Some(url) = node
+                    .children().into_iter()
+                        .filter(|x| x.name() == Some("td"))
+                        .filter(|x| x.attr("align") == Some("LEFT"))
+                        .flat_map(|x| x.children())
+                        .filter(|x| x.name() == Some("a"))
+                        .map(|x| x.attr("href"))
+                        .filter_map(|x| x)
+                    .collect::<Vec<_>>().get(0) {
+                        // println!("URL\t{:?}", url);
+                        auction.url = format!("http://egun.de/market/{}", url);
+
+                    }
                 
                     if let Some(remaining) = parse_end_date(
                         &node
@@ -128,7 +129,7 @@ fn parse_url(url: &str) -> Vec<Auction> {
                         .join(" ")
                     ){
                         // dbg!(&t_remaining.children());
-                        auction.gcal = date_to_gcal(remaining);
+                        auction.gcal = format!("http://www.google.com/calendar/event?action=TEMPLATE&dates={}&text={}&location=&details=", date_to_gcal(remaining), auction.desc);
                         auction.timestamp = remaining.timestamp();
                         // println!("ENDS\t{:?}", date_to_gcal(remaining));
 
@@ -146,3 +147,13 @@ fn parse_url(url: &str) -> Vec<Auction> {
 
         auctions
 }
+fn main() {
+    // let url = "http://www.egun.de/market/list_items.php?mode=qry&query=g36&plusdescr=off&plusdescr=on&wheremode=and&ewb=1&status=&minprice=&maxprice=&type=0&nick=&country_id=&zip=&int=0&order=ends&asdes=asc";
+    let url = "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off&wheremode=and&query=sniper&quick=1";
+    
+    // dbg!(parse_url(url));
+
+    // write out the file
+    let writer = BufWriter::new(File::create("db.json").unwrap());
+    serde_json::to_writer_pretty(writer, &parse_url(url)).unwrap();
+}

+ 83 - 0
test.html

@@ -0,0 +1,83 @@
+<!doctype html>
+<head>
+  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
+  <meta content="utf-8" http-equiv="encoding">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <meta name="mobile-web-app-capable" content="yes">
+  <meta name="theme-color" content="#dddddd">
+  <link rel="icon" sizes="128x128" href="icon.png">
+  
+  <style>
+    * {
+      margin: 0;
+      padding: 0;
+    }
+    #splash {
+      background-color: rgb(61, 61, 61);
+      color: rgb(207, 207, 207);
+      padding: 10%;
+      margin: 0%;
+      font-size: 4em;
+      font-weight: bolder;
+      padding-bottom: 200%;
+      height: 100%;
+      font-family: Arial, Helvetica, sans-serif;
+    }
+  </style>
+</head>
+
+
+<body>
+  <div id="splash">
+    loading
+  </div>
+  
+  
+  <div id="app" style="display: none">
+    <nav>
+      <!-- <img class="brand" src="icon-white.png"> -->
+      <div class="logo">{{title}}</div>
+      <template v-for="item in items" v-if="item.price == null">
+        <div style="font-size:0.6em; margin-left:70%;">
+          Updated: {{item.desc}}
+        </div>    
+      </template>
+      
+    </nav>
+    
+    
+    <div class="content">
+      
+      <template v-for="item in items" v-if="item.price != null">
+        <div class="panel">
+          <div class="grid-auto">
+            <div >
+              <img :src="item.thumb" style="vertical-align:middle;">
+            </div>
+            <div><a :href="item.url">{{item.desc}}</a></div>
+            <div>
+              <div class="badge">{{item.price}} EUR</div>
+            </div>
+            <div>Noch {{item.remaining}}</div>
+      <a v-bind:href="item.gcal">Add to cal</a>
+	  </div>
+        </div>
+      </template>
+      
+      
+      <!-- {{articles}} -->
+      
+    </div> 
+  </div>
+</body>
+
+
+<script defer src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.min.js"></script>
+<link rel="stylesheet" href="https://rawgit.com/woelper/lilac/master/lilac.min.css">
+<script defer src="app.js"></script>
+
+<style>
+  :root {
+    --main-color: #2e442f;
+  }
+</style>