superagent.get(juejinUrl) .end((err, obj) => { var msg = obj.body.d var totalCollectionsCount = msg.totalCollectionsCount //喜欢数 var totalViewsCount = msg.totalViewsCount //阅读数 console.log('实时喜欢数:' + totalCollectionsCount) console.log('实时阅读数:' + totalViewsCount) changeReadMe(totalCollectionsCount, totalViewsCount) })
// 机器人消息 router.get('/robotapi', (req, res) => { const response = res const info = req.query.info const userid = req.query.id const key = 'fde7f8d0b3c9471cbf787ea0fb0ca043' superagent.post('http://www.tuling123.com/openapi/api') .send({info, userid, key}) .end((err, res) => { if (err) { global.logger.error(err) } response.json({ data: res.text }) }) })
sendPeer(peer, peerToSend) { const URL = `${peer.url}/node/peers`; console.info(`Sending ${peerToSend.url} to peer ${URL}.`); return superagent .post(URL) .send(peerToSend) .catch((err) => { console.warn(`Unable to send me to peer ${URL}: ${err.message}`); }); }
getTransactions(peer) { const URL = `${peer.url}/blockchain/transactions`; let self = this; console.info(`Getting transactions from: ${URL}`); return superagent .get(URL) .then((res) => { self.syncTransactions(Transactions.fromJson(res.body)); }) .catch((err) => { console.warn(`Unable to get transations from ${URL}: ${err.message}`); }); }
sendLatestBlock(peer, block) { const URL = `${peer.url}/blockchain/blocks/latest`; console.info(`Posting latest block to: ${URL}`); return superagent .put(URL) .send(block) .catch((err) => { console.warn(`Unable to post latest block to ${URL}: ${err.message}`); }); }
getConfirmation(peer, transactionId) { // Get if the transaction has been confirmed in that peer const URL = `${peer.url}/blockchain/blocks/transactions/${transactionId}`; console.info(`Getting transactions from: ${URL}`); return superagent .get(URL) .then(() => { return true; }) .catch(() => { return false; }); }
sendTransaction(peer, transaction) { const URL = `${peer.url}/blockchain/transactions`; console.info(`Sending transaction '${transaction.id}' to: '${URL}'`); return superagent .post(URL) .send(transaction) .catch((err) => { console.warn(`Unable to put transaction to ${URL}: ${err.message}`); }); }
function delete_function(name, node) { superagent .post(scheme + node + ':' + agent_port + '/run') .send({ token: token, command: 'docker container rm -f ' + name }) .set('accept', 'json') .end((error, response) => { if (error) { console.log('\n' + error); } }); }
getBlocks(peer) { const URL = `${peer.url}/blockchain/blocks`; let self = this; console.info(`Getting blocks from: ${URL}`); return superagent .get(URL) .then((res) => { // Check for what to do with the block list self.checkReceivedBlocks(Blocks.fromJson(res.body)); }) .catch((err) => { console.warn(`Unable to get blocks from ${URL}: ${err.message}`); }); }
getLatestBlock(peer) { const URL = `${peer.url}/blockchain/blocks/latest`; let self = this; console.info(`Getting latest block from: ${URL}`); return superagent .get(URL) .then((res) => { // Check for what to do with the latest block self.checkReceivedBlock(Block.fromJson(res.body)); }) .catch((err) => { console.warn(`Unable to get latest block from ${URL}: ${err.message}`); }); }
// 机器人消息 app.get('/api/robotapi', (req, res) => { const response = res const info = req.query.info const userid = req.query.id const key = 'fde7f8d0b3c9471cbf787ea0fb0ca043' superagent.post('http://www.tuling123.com/openapi/api') .send({info, userid, key}) .end((err, res) => { if (err) { global.logger.error(err) } response.json({ data: res.text }) }) })