我想使用节点js和请求监视API的更改。我能够成功解析数据,然后进行控制台日志记录,但是我想对其进行设置,以便它在发生任何价格变化时提醒我,然后将其转储到不和谐的Webhook中。
到目前为止,我已经从API中提取了数据并将数据推送到了不和谐的Webhook,然后向我提醒了当前价格,但是除非重新运行该功能,否则我将无法监视更改。再次显示当前价格。
const request = require("request");
function discord(messages){
request({
url: "https://discordapp.com/api/webhooks/57143540025348169/notmyrealwebhook",
method: "POST",
json: messages
}),
function(body, response, error){
console.log(body);
if(error){
console.log(error);
}
};
}
const headers = {
"Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
"Upgrade-Insecure-Requests" : "1"
}
const options = {
url: "http://api.openmarketcap.com/api/v1/tokens",
headers: headers,
json: true
}
request(options, function(err, resp, body){
const data = body.data;
const consoleData = [];
for(i in data){
consoleData.push({"Name" : data[i].name, "Symbol" : data[i].symbol, "Price USD" : parseFloat(data[i].price_usd)});
}
console.log(consoleData);
});
基本上,我想使程序始终运行,并进行特定更改,然后将其发送到提供的webhook。任何建议或帮助,将不胜感激!