Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const zlib = require("zlib");
- const zmq = require("zeromq");
- const sock = zmq.socket("sub");
- const MongoClient = require('mongodb').MongoClient;
- // Connection URL
- const url = 'mongodb://localhost:27017';
- // Database Name
- const dbName = 'santu';
- sock.connect("tcp://eddn.edcd.io:9500");
- console.log("Worker connected to port 9500");
- sock.subscribe("");
- sock.on("message", topic => {
- const parsed = JSON.parse(zlib.inflateSync(topic));
- if (parsed.message.StarSystem === 'San Tu' || parsed.message.systemName === 'San Tu') {
- console.log(parsed.message.StarSystem || parsed.message.systemName);
- for (const i in parsed) {
- for (const x in parsed[i]) {
- if (i.startsWith('$')) {
- parsed[i.replace('$', '')] === parsed[i];
- delete parsed[i];
- }
- if (x.startsWith('$')) {
- parsed[x.replace('$', '')] === parsed[i][x];
- delete parsed[i][x];
- }
- }
- }
- MongoClient.connect(url, function(err, client) {
- console.log("Connected successfully to server");
- const db = client.db(dbName);
- db.collection('eddn')
- .insertOne(parsed, (err, res) => {
- if (err) {
- console.error(err);
- process.exit(1);
- } else {
- console.log('new san tu entry');
- }
- })
- client.close();
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment