-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
41 lines (32 loc) · 932 Bytes
/
index.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
require('dotenv').config();
const fetch = require("node-fetch");
const fs = require("fs");
const getPrice = async () => {
try {
const today = new Date().toISOString().slice(0, 10);
const response = await fetch(
"https://api.binance.us/api/v3/ticker/price?symbol=BTCUSDT"
);
const data = await response.json();
console.log("data", data);
const price = parseFloat(data.price).toFixed(2);
// console.log("today", today);
// console.log("price", price);
return {
today,
price,
};
} catch (err) {
console.error(err.message);
return {};
}
};
const generate = async () => {
const { today, price } = await getPrice();
if (!price) return;
fs.appendFileSync("README.md", `| ${today} | ${price} |\r\n`);
const deno = `${process.env.DENO_URL}?db=${process.env.DATABASE_ID}&today=${price}`;
console.log('deno', deno);
await fetch(deno);
};
generate();