Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dhaka stock exchange current price scraping & saving them in memcache. Used modules "memcache" & "dse-bd"
/* Initializing memcache client */
var host = 'localhost', port = 11212;
var memcache = require('memcache'),
client = new memcache.Client(host, port);
client.port = host
client.host = port;
client.on('connect', function(){ console.log("we've connected"); });
client.on('close', function(){ console.log("connection has been closed"); });
client.on('timeout', function(){ console.log("socket timed out"); });
client.on('error', function(){ console.log("there was an error"); });
client.connect()
/* DSE scraping options */
var options = {
instant : true,
keepAlive: true,
interval : 1000*60
};
/* fetching stock prices & save them in memcache*/
var dsebd = require('dse-bd').getShareInfo(function(data, b){
for(var i in data){
var stock = data[i], code = stock.index;
client.set(code, JSON.stringify(stock), function(error, result){}, 1000);
}
},options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment