@icgio/icg-utils 1.9.25 → 1.9.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +0 -2
- package/lib/ip.js +17 -1
- package/package.json +1 -4
- package/lib/html-parser.js +0 -66
- package/lib/rate-limit-logger.js +0 -31
package/index.js
CHANGED
|
@@ -2,14 +2,12 @@ module.exports = {
|
|
|
2
2
|
coinmarketcap: require('./lib/crypto-rates.js'),
|
|
3
3
|
coingecko: require('./lib/crypto-rates.js'),
|
|
4
4
|
forex_rate: require('./lib/forex-rate.js'),
|
|
5
|
-
html_parser: require('./lib/html-parser.js'),
|
|
6
5
|
influx: require('./lib/influxdb.js'),
|
|
7
6
|
ip: require('./lib/ip.js'),
|
|
8
7
|
logger: require('./lib/logger.js'),
|
|
9
8
|
mail: require('./lib/mail.js'),
|
|
10
9
|
observable: require('./lib/observable.js'),
|
|
11
10
|
ohlcv: require('./lib/ohlcv'),
|
|
12
|
-
rate_limiter_logger: require('./lib/rate-limit-logger.js'),
|
|
13
11
|
rate_limiter: require('./lib/rate-limiter.js'),
|
|
14
12
|
utils: require('./lib/utils.js'),
|
|
15
13
|
constants: {
|
package/lib/ip.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Get external IP address using ipify.org API
|
|
3
|
+
* @returns {Promise<string>} The external IP address
|
|
4
|
+
*/
|
|
5
|
+
async function getIP() {
|
|
6
|
+
try {
|
|
7
|
+
const response = await fetch('https://api.ipify.org?format=json')
|
|
8
|
+
if (!response.ok) {
|
|
9
|
+
throw new Error(`HTTP error! status: ${response.status}`)
|
|
10
|
+
}
|
|
11
|
+
const data = await response.json()
|
|
12
|
+
return data.ip
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error('Error fetching external IP:', error.message)
|
|
15
|
+
throw error
|
|
16
|
+
}
|
|
17
|
+
}
|
|
2
18
|
|
|
3
19
|
module.exports = getIP
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.27",
|
|
4
4
|
"description": "Utils package.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -23,12 +23,9 @@
|
|
|
23
23
|
"@influxdata/influxdb-client": "^1.35.0",
|
|
24
24
|
"@influxdata/influxdb-client-apis": "^1.35.0",
|
|
25
25
|
"csv-parse": "^5.6.0",
|
|
26
|
-
"external-ip": "^2.3.1",
|
|
27
|
-
"htmlparser2": "^3.10.1",
|
|
28
26
|
"lodash": "^4.17.21",
|
|
29
27
|
"mailgun-js": "^0.22.0",
|
|
30
28
|
"needle": "^3.3.1",
|
|
31
|
-
"qrcode-terminal": "^0.12.0",
|
|
32
29
|
"websocket": "^1.0.35",
|
|
33
30
|
"winston": "^2.4.5",
|
|
34
31
|
"ws": "^8.18.3"
|
package/lib/html-parser.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const htmlparser = require('htmlparser2')
|
|
2
|
-
const needle = require('needle')
|
|
3
|
-
|
|
4
|
-
function tag_parser(body, tag_name, tag_attrs, cb) {
|
|
5
|
-
let result = []
|
|
6
|
-
let parser = new htmlparser.Parser(
|
|
7
|
-
{
|
|
8
|
-
onopentag: (name, attrs) => {
|
|
9
|
-
let flag = true
|
|
10
|
-
for (let tag_attr in tag_attrs) {
|
|
11
|
-
if (!attrs[tag_attr] || tag_attrs[tag_attr] !== attrs[tag_attr]) flag = false
|
|
12
|
-
}
|
|
13
|
-
if (flag && name === tag_name) {
|
|
14
|
-
result.push(attrs)
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
onend: () => {
|
|
18
|
-
cb(result)
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
{ decodeEntities: true }
|
|
22
|
-
)
|
|
23
|
-
parser.write(body)
|
|
24
|
-
parser.end()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function text_parser(body, include_new_line = false, cb) {
|
|
28
|
-
let result = []
|
|
29
|
-
let parser = new htmlparser.Parser(
|
|
30
|
-
{
|
|
31
|
-
ontext: (text) => {
|
|
32
|
-
if (!include_new_line && !text.startsWith('\n')) result.push(text)
|
|
33
|
-
},
|
|
34
|
-
onend: () => {
|
|
35
|
-
cb(result)
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{ decodeEntities: true }
|
|
39
|
-
)
|
|
40
|
-
parser.write(body)
|
|
41
|
-
parser.end()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function html_parser(url, options, cb) {
|
|
45
|
-
let tag_name = options.tag_name
|
|
46
|
-
let tag_attrs = options.tag_attrs
|
|
47
|
-
let text = options.text
|
|
48
|
-
let text_include_new_line = options.text_include_new_line
|
|
49
|
-
if (tag_name && tag_attrs && text) {
|
|
50
|
-
console.error('unable to parse tag and text at the same time')
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
if (tag_name && tag_attrs) {
|
|
54
|
-
needle.get(url, (res, err, body) => {
|
|
55
|
-
tag_parser(body, tag_name, tag_attrs, cb)
|
|
56
|
-
})
|
|
57
|
-
} else if (text) {
|
|
58
|
-
needle.get(url, (res, err, body) => {
|
|
59
|
-
text_parser(body, text_include_new_line, cb)
|
|
60
|
-
})
|
|
61
|
-
} else {
|
|
62
|
-
console.error('wrong options')
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = html_parser
|
package/lib/rate-limit-logger.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
class RateLimitedLogger {
|
|
2
|
-
constructor(defaultLimit = 1000) {
|
|
3
|
-
this.defaultLimit = defaultLimit
|
|
4
|
-
this.lastLogTime = 0
|
|
5
|
-
this.lastErrorTime = 0
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
log(message, limit = this.defaultLimit) {
|
|
9
|
-
this._rateLimitedOutput(console.log, message, limit, 'log')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
error(message, limit = this.defaultLimit) {
|
|
13
|
-
this._rateLimitedOutput(console.error, message, limit, 'error')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
_rateLimitedOutput(outputFunction, message, limit, type) {
|
|
17
|
-
const now = Date.now()
|
|
18
|
-
const lastTime = type === 'log' ? this.lastLogTime : this.lastErrorTime
|
|
19
|
-
|
|
20
|
-
if (now - lastTime >= limit) {
|
|
21
|
-
outputFunction(message)
|
|
22
|
-
if (type === 'log') {
|
|
23
|
-
this.lastLogTime = now
|
|
24
|
-
} else {
|
|
25
|
-
this.lastErrorTime = now
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = RateLimitedLogger
|