-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
116 lines (104 loc) · 3.52 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Quibids</title>
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css">
<style type="text/css">
#webpage {
width: 100%;
height: 370px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/pouchdb/2.2.3/pouchdb.min.js"></script>
<script type="text/javascript">
var docs = [];
var table;
var db = new PouchDB('QuibidsDB');
function clearDB() {
db.destroy(dump);
db = new PouchDB('QuibidsDB');
}
function parse() {
$body = $("#webpage").contents().find("body").first();
if ($body.find(".list.active").length != 0) {
$body.find(".auction-item-wrapper").each(scrape);
if (docs.length) {
db.bulkDocs(docs, dump);
docs = [];
}
setTimeout(refreshIframe, 180000);
}
}
function refreshIframe() {
var iframe = document.getElementById("webpage");
iframe.src = iframe.src;
}
function scrape(index, element) {
$root = $(element).children().first();
var auction = {
_id: $root.attr("id"),
name: $root.find(".auction-item-title").first().text(),
price: parseFloat($root.find(".price").first().text().substring(1)),
value: parseFloat($root.find("#valueprice").text().substring(1)),
bidomatic: $root.find(".bidomatic-on").length != 0,
gameplay: $root.find(".gameplay-on").length != 0,
timestamp: Date.now()
};
// check that data isn't void
if (auction.name.length) {
docs.push(auction);
}
}
function dump(err, response) {
if (err)
console.log(err);
else
console.log(response);
}
function queryCallback(err, results) {
if (err)
console.log(err);
else {
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows[i];
table.row.add([row.key[0], row.key[1], row.value.sum / row.value.count, Math.sqrt(row.value.sumsqr / row.value.count), row.value.count]);
}
table.draw();
}
}
function map(doc) {
emit([doc.name, doc.value], doc.price);
}
$(document).ready(function() {
table = $("#table").DataTable({
"columns": [{
"title": "Name"
}, {
"title": "Value"
}, {
"title": "Avg"
}, {
"title": "σ"
}, {
"title": "Count"
}]
});
db.query({
map: map,
reduce: "_stats"
}, {
group: true
}, queryCallback);
});
</script>
</head>
<body>
<iframe id="webpage" onload="setTimeout(parse, 3000)" src="http://www.quibids.com/en/auctions-completed/"></iframe>
<table id="table"></table>
<!-- Keep hidden to avoid misclicks and crying -->
<input onclick="clearDB()" type="button" value="Clear DB"></input>
</body>
</html>