const sqlite3 = require('sqlite3').verbose(); const db = new sqlite3.Database('./db'); const dates = `2024-09-03 2024-09-04 2024-09-05 2024-09-06 2024-09-07 2024-09-08 2024-09-09 2024-09-10 2024-09-11 2024-09-12 2024-09-13 2024-09-14 2024-09-15 2024-09-16 2024-09-17 2024-09-18 2024-09-19 2024-09-20 2024-09-21 2024-09-22 2024-09-23 2024-09-24 2024-09-25 2024-09-26 2024-09-27 2024-09-28 2024-09-29 2024-09-30 2024-10-01 2024-10-02 2024-10-03 2024-10-04 2024-10-05 2024-10-06 2024-10-07 2024-10-08 2024-10-09 2024-10-10 2024-10-11 2024-10-12 2024-10-13 2024-10-14 2024-10-15 2024-10-16 2024-10-17 2024-10-18 2024-10-19 2024-10-20 2024-10-21 2024-10-22 2024-10-23 2024-10-24 2024-10-25 2024-10-26 2024-10-27 2024-10-28 2024-10-29 2024-10-30 2024-10-31 2024-11-01 2024-11-02 2024-11-03 2024-11-04 2024-11-05 2024-11-06 2024-11-07 2024-11-08 2024-11-09 2024-11-10 2024-11-11 2024-11-12 2024-11-13 2024-11-14 2024-11-15 2024-11-16 2024-11-17 2024-11-18 2024-11-19 2024-11-20 2024-11-21 2024-11-22 2024-11-23 2024-11-24 2024-11-25 2024-11-26 2024-11-27 2024-11-28 2024-11-29 2024-11-30 2024-12-01 2024-12-02 2024-12-03 2024-12-04 2024-12-05 2024-12-06 2024-12-07 2024-12-08 2024-12-09 2024-12-10 2024-12-11 2024-12-12 2024-12-13 2024-12-14 2024-12-15 2024-12-16 2024-12-17 2024-12-18 2024-12-19 2024-12-20 2024-12-21 2024-12-22 2024-12-23 2024-12-24 2024-12-25 2024-12-26 2024-12-27 2024-12-28 2024-12-29 2024-12-30 2024-12-31 2025-01-01 2025-01-02 2025-01-03 2025-01-04 2025-01-05 2025-01-06 2025-01-07 2025-01-08 2025-01-09 2025-01-10 2025-01-11` function formatDate(date) { // Extract the day, month, and year from the date let day = date.getDate(); // Get the day let month = date.getMonth() + 1; // Get the month (0-based index, so add 1) let year = date.getFullYear(); // Get the full year // Add leading zero to day and month if needed day = day < 10 ? '0' + day : day; month = month < 10 ? '0' + month : month; // Return the formatted date return `${day}-${month}-${year}`; } const wait = async function() { await new Promise((res) => { setTimeout(() => { res(); }, 60000); }) } db.serialize(async () => { // db.run("CREATE TABLE assets (asset TEXT, price VALUE, date DATE)"); const params = dates.split('\n'); for(i in params) { if(i % 5 == 0) { await wait(); } const param = params[i] const stmt = db.prepare("INSERT INTO assets VALUES (?, ?, ?)") const date = new Date(param) const formattedDate= formatDate(date); const response = await fetch(`https://api.coingecko.com/api/v3/coins/ethereum/history?date=${formattedDate}`) const data = await response.json() const price = Number(data.market_data.current_price.rub) stmt.run("ETH", price, date) stmt.finalize(); console.log(param); } db.each("SELECT * FROM assets", (err, row) => { console.log(row); }); });