-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
62 lines (54 loc) · 1.56 KB
/
index.js
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
var makeUri, run, county;
makeUri = function(query, supplement) {
return "http://search.twitter.com/search.json?rpp=100&q=" + query + "%20AND%20" + supplement;
};
county = function(array) {
var i = 0;
array.forEach(function(entry) {
if (new Date() > Date.parse(entry.created_at) + 3600 * 1000 * 24)
i++;
});
return i;
};
run = function(stock, done) {
var negative, positive, trimToJson;
positive = ["buy", "long", "bullish"];
negative = ["sell", "short", "bearish"];
uri = makeUri("$" + stock, positive.join("%20OR%20"));
return $.ajax({
url: uri,
type: "GET",
dataType: "jsonp"
}).done(function(pdata) {
return $.ajax({
url: makeUri("$" + stock, negative.join("%20OR%20")),
type: "GET",
dataType: "jsonp"
}).done(function(ndata) {
return done({
pcount: county(pdata.results),
ncount: county(ndata.results),
stock: stock
});
}).fail(function(err) {
return console.log("fail on negative", err);
});
}).fail(function(err) {
return console.log("fail on positive", err);
});
};
$(function() {
$('.stock-input').on("keypress", function(evt) {
if (evt.charCode !== 13) return;
$('.loader').show();
$results = $('#results').hide();
run($(this).val(), function(result) {
console.log(result);
$('.loader').hide();
$results.find('.stock').html(result.stock);
$results.find('.positive').html(result.pcount);
$results.find('.negative').html(result.ncount);
$results.show().removeClass("loading");
});
});
});