-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
59 lines (42 loc) · 1.46 KB
/
main.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
const axios = require('axios')
const cheerio = require('cheerio');
const express = require('express')
const cors = require('cors')
async function getPrice() {
try {
const url = 'https://blockchain.info/ticker'
const { data } = await axios({
method: "GET",
url: url,
})
const circularReference = data;
circularReference.myself = circularReference;
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
const stringified = JSON.stringify(circularReference, getCircularReplacer());
const re = new RegExp(/("USD":{"15m":[^\,]+)/g);
const datastring = stringified.match(re);
let newString = datastring.toString()
newString = newString.replace(/({)/g,'');
newString2 = 'The Current Price of Bitcoin ' + newString
String.prototype.InsertAt=function(CharToInsert,Position){
return this.slice(0,Position) + CharToInsert + this.slice(Position)
}
newString3 = newString2.InsertAt(' $', 41)
console.log(newString3);
}
catch (error) {
console.error(error);
}
}
getPrice()