forked from nitintangellamudi/EbayPricingTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
183 lines (166 loc) · 6.08 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html>
<head>
<title>EADB | Ebay Sold Item Analysis</title>
<style type="text/css">
body {
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="styles.css" />
<link rel="shortcut icon" type="image/png" href="images/ebayPricingLogoII.png" />
</head>
<body>
<div id="mainBanner">
<img src="images/ebayPricingLogo.png" a href="/index.html">
<h2 id="title" onClick="changetext()">EADB | Ebay Sold Item Analysis</h2>
<div>
<label for="search" color='#e15e5b'>Search for an item </label>
<div id="searchDiv">
<input type="text" id="search" placeholder="Enter Item">
</div>
<div id="minPriceDiv">
<input type="number" id="minPrice" placeholder="Minimum Price?" onClick="0">
</div>
</div>
<div>
<button id="submit" onClick="updateList()">Submit</button>
<button id="refresh" onClick="location.href=location.href">Refresh</button>
</div><br>
<div id="averagePrice"></div>
</div>
<div id="graph">
<canvas id="mycanvas" width="50px" height="40px"></canvas>
</div>
<div id="results">
<div id="results">
</div>
<div>
<h3 id="itemOutput">
</h3>
</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.min.js"></script>
<script>
// Create our number formatter.
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
// the default value for minimumFractionDigits depends on the currency
// and is usually already 2
});
var priceData = [];
var sum = 0;
var count = 0;
var avgPrice = 0;
// Parse the response and build an HTML table to display search results
function changetext() {
document.getElementById("title").innerHTML = "It Worked!"
}
function _cb_findItemsByKeywords(root) {
var items = root.findCompletedItemsResponse[0].searchResult[0].item || [];
document.getElementById("itemOutput").innerHTML = JSON.stringify(items[0]);
var html = [];
html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
// var price = item.paymentMethod;
// var sellState = 1;
var price = item.sellingStatus[0].currentPrice[0].__value__;
var sellState = item.sellingStatus[0].sellingState;
if (sellState == "EndedWithSales") {
var sellState = 'Sold';
}
if (null != title && null != viewitem) {
priceData.push(parseFloat(price));
sum += parseFloat(price);
count += 1;
html.push('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' +
'<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td>' +
'<td>' + price + '</td>' + '<td>' + sellState + '</td>' /*+'<td><button onclick="moreLikeThis()">More Like This!</button>'+
+'</td>'*/+ '</tr>');
}
}
// Split the price data into 10 intervals, have frequencies within intervals
var ub = Math.max.apply(null, priceData);
var lb = Math.min.apply(null, priceData);
var increment = (ub - lb) / 10;
var intervals = [];
var frequency = [];
intervals.push(lb);
for (var j = 1; j < 11; ++j) {
var counter = 0;
// Make names for labels,
// var name = "label '"+i+"'";
intervals.push(intervals[j - 1] + increment);
for (var i = 0; i < priceData.length; ++i) {
if (priceData[i] > intervals[j - 1] && priceData[i] <= intervals[j]) {
counter += 1;
}
}
frequency.push(counter);
}
avgPrice = sum / count;
html.push('</tbody></table>');
document.getElementById("title").innerHTML = frequency;
document.getElementById("results").innerHTML = html.join("");
document.getElementById("averagePrice").innerHTML = avgPrice;
makeGraph(intervals, frequency);
} // End _cb_findItemsByKeywords() function
function updateList() {
var keywrd = encodeURIComponent(document.getElementById("search").value);
var minimumPrice = encodeURIComponent(document.getElementById("minPrice").value);
document.getElementById("title").innerHTML = keywrd;
var url = "http://svcs.ebay.com/services/search/FindingService/v1";
url += "?OPERATION-NAME=findCompletedItems";
url += "&SERVICE-VERSION=1.0.0";
url += "&SECURITY-APPNAME=NitinTan-AverageS-PRD-15d80d3bd-86aa9832";
url += "&GLOBAL-ID=EBAY-US";
url += "&RESPONSE-DATA-FORMAT=JSON";
url += "&callback=_cb_findItemsByKeywords";
url += "&REST-PAYLOAD";
url += "&keywords=";
url += keywrd;
url += "&itemFilter(0).name=MinPrice";
url += "&itemFilter(0).value="
url += minimumPrice;
url += "&itemFilter(1).name=SoldItemsOnly"
url += "&itemFilter(1).value=true"
url += "&paginationInput.entriesPerPage=50";
// Submit the request
s = document.createElement('script'); // create script element
s.src = url;
document.body.appendChild(s);
}
function makeGraph(intervals, frequency) {
console.log("ready!");
var ctx = $('#mycanvas').get(0).getContext('2d');
//pie chart data
var labelNames = ["Corn Flower", "Light Green", "Orange"];
// var numbers=[270,50,40];
var backgroundcolor = ["cornflowerblue", "lightgreen", "orange"];
var highlightcolor = ["lightskyblue", "yellowgreen", "darkorange"];
//draw
var piechart = new Chart(ctx,
{
type: 'bar',
data: {
labels: intervals,
datasets: [{
backgroundColor: backgroundcolor,
highlight: highlightcolor,
data: frequency
}]
}
});
};
function moreLikeThis() {
}
</script>
</html>