Skip to content

Commit

Permalink
Latest..
Browse files Browse the repository at this point in the history
  • Loading branch information
Flinn committed Nov 10, 2013
1 parent 15561ad commit ca7c368
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 41 deletions.
4 changes: 4 additions & 0 deletions psychsignal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ var request = require('request'),

module.exports = function get_sentiments(symbol, startDate,endDate, fn){

console.log("load sentiments");

var url = _s.sprintf("https://psychsignal.com/api/sentiments?api_key=41910b4ec81feab42407b3270cb629d0&symbol=%s&from=%s&to=%s&period=d", symbol, startDate, endDate);

console.log(url);

request({url:url, json:true}, function (error, response, contents) {

if (!error && response.statusCode == 200) {
Expand Down
7 changes: 1 addition & 6 deletions quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ module.exports = function get_quotes(symbol, startDate, endDate, fn){
request({url:url, json:true}, function (error, response, contents) {

if (!error && response.statusCode == 200) {

var data = {
"quotes": contents.GlobalQuotes
};

return fn(null, data);
return fn(null, contents.GlobalQuotes);
}
});
};
Expand Down
106 changes: 84 additions & 22 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,87 @@
exports.index = function(req, res){
var model = {};
var stocksList = [];
var load_sentiments = require('../psychsignal'),
load_fool_content = require('../fool'),
load_quotes = require('../quotes'),
async = require('async'),
load_trending_symbols = require('../stocktwits').get_trending_symbol;

var myStocks = ["MSFT","AAPL","SEIC","GOOG","NFLX","DVN","RAX","TSLA","AMEX"];

for(var i=0;i <= myStocks.length -1; i++)
{
var stock = {"rank":i+1,
"symbol":myStocks[i],
"idea_num":15,
"cap_stars": [1,2],
"non_cap_stars": [3,4,5],
"bullish":150,
"bearish":40};

stocksList.push(stock);
}

model.stocks = stocksList;
exports.index = function(req, res) {

res.render('index', {
data: model
var myStocks = ["MSFT", "AAPL", "GOOG"];
var final_data = [];

myStocks.forEach(function(stock){

var results = {};

async.waterfall([

function(callback){
results.symbol = stock;

load_sentiments(stock, '2013-07-01', '2013-10-31', function(err, contents){

results.sentiments = contents;
callback(null, results);
})
},
function(results, callback) {

load_quotes(stock, '2013-07-01', '2013-10-31', function(err, contents){
results.quotes = contents;
callback(null, results);
})
},
function(results, callback) {

load_trending_symbols(function(err, contents){
results.trendingsymbols = contents;
final_data.push(results);

callback(null, final_data);
})
}
], function(err, results){

var rows = [];

results.forEach(function(result){

var idea_count = Math.floor((Math.random() * 30) + 1);

var caps_star_count = Math.floor((Math.random() * 5) + 1);
var non_caps_star_count = 5 - caps_star_count;

var caps_stars = [];
var non_caps_stars = [];

for (var z = 1; z <= caps_star_count; z++) {
caps_stars.push("star");
}
for (var y = 0; y < non_caps_star_count; y++) {
non_caps_stars.push("not");
}

// console.log(results.sentiments);

var row = {
"rank": 0,
"symbol": result.symbol,
"idea_num": idea_count,
"sentimetric": 5,
"price": result.quotes[0].LastClose,
"cap_stars": caps_stars,
"non_cap_stars": non_caps_stars,
"bullish": result.sentiments.bullish[0].value,
"bearish": result.sentiments.bearish[0].value
};

rows.push(row);
});

console.log(rows);

res.render('index', {data: rows});
});
});
};

};
10 changes: 7 additions & 3 deletions routes/stocks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
exports.index = function(req, res){


exports.index = function(req, res) {
res.render('index', {});
};

}
exports.my_stocks = function(req, res){
var myStocks = ["MSFT","AAPL","SEIC","GOOG","NFLX","DVN","RAX","TSLA","AMEX"];
res.json(myStocks);
};
26 changes: 16 additions & 10 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,29 @@ <h3 style="margin-top: -10px;">Leaders</h3>
</tr>
</thead>
<tbody>
{% for stock in data.stocks %}


{% for row in data %}
{{JSON.parse(row)}}
{% endfor %}

{% for row in data %}
<tr>
<td><strong>{{ stock.rank }}</strong></td>
<td>{{ stock.symbol }}</td>
<td>{{ stock.sentimetric }}</td>
<td>{{ stock.price }}</td>
<td>{{ stock.bullish }}</td>
<td>{{ stock.bearish }}</td>
<td><strong>{{ row.rank }}</strong></td>
<td>{{ row.symbol }}</td>
<td>{{ row.sentimetric }}</td>
<td>{{ row.price }}</td>
<td>{{ row.bullish }}</td>
<td>{{ row.bearish }}</td>
<td>
{% for star in stock.cap_stars %}
{% for star in row.cap_stars %}
<span style="color: #f1c40f" class="fui-star-2"></span>
{% endfor %}
{% for star in stock.non_cap_stars %}
{% for star in row.non_cap_stars %}
<span style="color: #bdc3c7" class="fui-star-2"></span>
{% endfor %}
</td>
<td><span class="badge">{{ stock.idea_num }}</span></td>
<td><span class="badge">{{ row.idea_num }}</span></td>
<td><a class="btn btn-xs btn-info" href="/snapshot/{{ stock.symbol }}">Details</a></td>
</tr>
{% endfor %}
Expand Down

0 comments on commit ca7c368

Please sign in to comment.