-
Notifications
You must be signed in to change notification settings - Fork 0
/
axios-client.js
93 lines (74 loc) · 2.48 KB
/
axios-client.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
83
84
85
86
87
88
89
90
91
92
93
/* axios-client for getting data from sanic servet at port 5555
* (C:\mat-dir\playground\sanic-stuff\sanic-app.py)
* refer to zmq-client.js
*/
// const zmq = require('zeromq')
const axios = require('axios')
const logger = require('tracer').colorConsole({
// format: '{{timestamp}} <{{title}}>{{file}}:{{line}}: {{message}}',
dateformat: 'HH:MM:ss.L',
level: process.env.TRACER_DEBUG || 'info' // set TRACER_DEBUG=debug
})
const file2lines = require('./src/file2lines')
const genRowdata = require('./src/genRowdata')
// const zmqAlign = require('./src/zmqAlign')
// const file1 = './data/test-en.txt'
// const file2 = './data/test-zh.txt'
const file1 = './data/射雕英雄传-en.txt'
const file2 = './data/射雕英雄传-zh.txt'
const lines1 = file2lines(file1).slice(0, 1000)
const lines2 = file2lines(file2).slice(0, 1000)
// debug('file1: %O', lines1.slice(0, 3))
// debug('file2: %O', lines2.slice(0, 3))
logger.debug('file1: %j', lines1.slice(0, 3))
logger.debug('file2: %j', lines2.slice(0, 3))
const port = 5555
// const port = 7777
// async function run () {
const run = async () => {
// logger.debug('sock (new zmq.Request) bound to port %s', port)
logger.debug('axios to visit 127.0.0.1 port %s', port)
// let msg = [lines1, lines2]
// await sock.send(JSON.stringify(msg))
// const [result] = await sock.receive()
const texts = [lines1.join('\n'), lines2.join('\n')]
let res
try {
// let _ = await axios.post(`http://127.0.0.1:${port}/post`, msg)
// let _ = await axios.post(`http://127.0.0.1:${port}/post/`, msg)
// let _ = await axios.post(`http://127.0.0.1:${port}/post/`, ['a', 'b'])
// let _ = await axios.post(`http://127.0.0.1:${port}/post/`, texts)
let _ = await axios.post(`http://forindo.net:${port}/post/`, texts)
res = _.data
} catch (e) {
let text1 = e.name
let text2 = e.message
res = { text1, text2 }
// throw e.name + ' ' + e.message
// throw 'bummer...'
}
logger.debug('res: ', res)
// const r = JSON.parse(result)
// let [col1, col2] = res.content
// let [col1, col2] = res
// logger.debug(col1.slice(0, 5))
// logger.debug(col2.slice(0, 4))
let ali
try {
ali = genRowdata({ col1: res, isRow: true })
} catch (e) {
text1 = e.name
text2 = e.message
metric = ''
ali = [{ text1, text2, metric }]
}
try{
logger.debug('\nrun - ali: \n\t%j', ali.slice(0, 7))
} catch (e) {
logger.error(e.message)
}
ali.forEach((el, i) => {
if (i < 10) logger.info(i, el)
})
}
run()