forked from qiguyu/hangqingreciever
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreciver.js
83 lines (80 loc) · 3.44 KB
/
reciver.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var settings = require('./etc/settings');
var queue = require('queuer');
var q = queue.getQueue(settings.queue.host, settings.queue.contentqueue);
var request = require('request');
var express = require('express');
var app = express.createServer();
app.use(express.bodyParser());
var MySqlClient = require('./lib/mysql').MySqlClient;
var mysql = new MySqlClient(settings.mysql.host, settings.mysql.port, settings.mysql.username, settings.mysql.password, settings.mysql.database);
app.post('/hangqing', function(req, res) {
var myDate = new Date();
var iTimestring = Date.parse(myDate) / 1000;
var myHour = myDate.getHours();
if(myHour < 11) {
var showtype = '开盘';
} else if(myHour > 14) {
var showtype = '收盘';
} else {
var showtype = '午盘';
}
var amount = req.body.volum;
if(amount > 100000) {
amount = amount / 10000;
amount = amount.toFixed(2);
amount += '万';
}
amount += '手';
var volum = req.body.amount;
if (volum > 100000000) {
volum = volum / 100000000;
volum = volum.toFixed(2);
volum += '亿';
} else if(volum > 100000) {
volum = volum / 10000;
volum = volum.toFixed(2);
volum += '万';
}
volum += '元';
var content = '【'+req.body.name+showtype+'播报】昨收:'+req.body.close+',今开:'+req.body.open+',最高:'+req.body.high+',最低:'+req.body.low+',最新:'+req.body.price+',涨跌额:'+req.body.updown+',涨跌幅:'+req.body.markup+'%,总量:'+amount+',金额:'+volum+'。';
if( myHour > 10 && req.body.type == 0) {
var stockcode = req.body.stockcode.substr(-6);
request({ uri:settings.zjlx+stockcode }, function (error, response, body) {
if(error) {
console.log('request error:'+stockcode);
res.end('error! request error:'+stockcode);
return;
}
if(response.statusCode != 200) {
res.end('error! status error:'+stockcode);
return;
}
try {
var oData = JSON.parse(body);
content += '【资金流向】净流量:' + oData.stock.fundquantity + '万元,其中机构:'+oData.stock.jigou.jigouquantity+'万元,大户'+oData.stock.dahu.dahuquantity+'万元,散户'+oData.stock.sanhu.sanhuquantity+'万元。';
mysql.insert_micro_blog(req.body.stockcode, iTimestring, content, function(blogid) {
if(blogid > 0) {
q.enqueue('mysql://'+settings.mysql.host+':'+settings.mysql.port+'/'+settings.mysql.database+'?micro_blog#'+blogid);
res.end('success');
} else {
res.end('error! insert error:'+stockcode);
}
});
} catch(err) {
console.log('parse error12:'+stockcode);
res.end('error! parse error:'+stockcode);
return;
}
});
} else {
mysql.insert_micro_blog(req.body.stockcode, iTimestring, content, function(blogid) {
if(blogid > 0) {
q.enqueue('mysql://'+settings.mysql.host+':'+settings.mysql.port+'/'+settings.mysql.database+'?micro_blog#'+blogid);
res.end('success');
} else {
res.end('error! insert error:'+stockcode);
}
});
}
});
app.listen(9559);