From ddea84624b900efa1c7158cd8608b2a1d770cafb Mon Sep 17 00:00:00 2001 From: Serafim Date: Mon, 13 Jan 2025 01:15:31 +0300 Subject: [PATCH] db replenishment scripts --- .gitignore | 2 +- db | Bin 8192 -> 8192 bytes repl/create.js | 6 ++ index.js => repl/index.js | 97 +++++++++++++------- package-lock.json => repl/package-lock.json | 0 package.json => repl/package.json | 0 repl/select.js | 10 ++ 7 files changed, 82 insertions(+), 33 deletions(-) create mode 100644 repl/create.js rename index.js => repl/index.js (60%) rename package-lock.json => repl/package-lock.json (100%) rename package.json => repl/package.json (100%) create mode 100644 repl/select.js diff --git a/.gitignore b/.gitignore index 3c3629e..e84c3fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -node_modules +*/node_modules diff --git a/db b/db index 8576a2e45b5ce16dae83e688356e66a07a97d337..57868073ab100741e7b8b8d3586c722458f3fed1 100644 GIT binary patch literal 8192 zcmeI#XH*pD8VB&_*B4F<4L{Sh1jjfTFGnf?cF23U&cI1T{u5mdng+G)4p^ z=86q57$dP`L8D%YEyQlDV8I$OQSY7HocFyS^Ywn#ng7f=^PlJ_drEqe zZNl`_sR`+}4&V%k5NxvnK)$>v2g&jt-JGd&@3N>V~vT2gx2U*C$* zA>ko0;kKBN-u7_YUuJ9d-?c3!d_;_&ZANO!xFp-K5c|+@Kil{O`JF#Z{)6wI@8;{V z0xZ>*^Ok*4<5o zNit=al1zh4fhLi3Q)Wyl$Nw0dTx~4j=DpsvgWvM2r2CD*9UMh{U zR{68?kaDx~AIdq(IAvd@ztU6jZ^Z+}ImP#i0!6lBx?;GZm!hS@f^YDq9NquJphZno zZW^cXn1~S1p4Y!W1ZH&j46XuN)R=o~uNj+4W6|N|n<0B6<{m|{fx%H1(9uw7lf5Bx zT5kv{ZRd#&_iM*wZ@~SDd&}7^U!udZCs}qY_xWWzcK?=*4t=gsc2DN+p#`(U)tAxX zlu{zQ2Xl)4A);70#j|55-H!E> z-NM|nZQp&Ts&}Dut#hU9X6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qKD=H@jh<4p_(J@NkCzczaJ2<<8ji+&JxO zO;W?wD0G}255$|ecG0wNL&M}t?B7oX#EZDDcu?_fyBdYo&5D3{57%j$ybL@Oih|EO zI}oqohAVmfT4k?6!Ryj9Al|~wgR>r9ezyaKhC3ZVyo6gCy|9PN&tid=bphfX+_|j( z0P=f`f^*_EAYQ?p>!u#)dsV)x3_%NlcmsE7QBZQeNIpxohYt`h;4Ya@AG8b>P=MN# F@E-+8p-2D# delta 34 qcmZp0XmFSy&8RX_#+gxNW5N=CW@Vn+li3B_Hx~BtY`!g{$_xOu=L)p| diff --git a/repl/create.js b/repl/create.js new file mode 100644 index 0000000..4584896 --- /dev/null +++ b/repl/create.js @@ -0,0 +1,6 @@ +const sqlite3 = require('sqlite3').verbose() +const db = new sqlite3.Database('../db') + +db.serialize(async () => { + db.run("CREATE TABLE assets (asset TEXT, price VALUE, date DATE)") +}) diff --git a/index.js b/repl/index.js similarity index 60% rename from index.js rename to repl/index.js index 42b4d3c..0418cc5 100644 --- a/index.js +++ b/repl/index.js @@ -1,7 +1,43 @@ -const sqlite3 = require('sqlite3').verbose(); -const db = new sqlite3.Database('./db'); +const sqlite3 = require('sqlite3').verbose() +const db = new sqlite3.Database('../db') -const dates = `2024-09-03 +const dates = +`2024-07-30 +2024-07-31 +2024-08-01 +2024-08-02 +2024-08-03 +2024-08-04 +2024-08-05 +2024-08-06 +2024-08-07 +2024-08-08 +2024-08-09 +2024-08-10 +2024-08-11 +2024-08-12 +2024-08-13 +2024-08-14 +2024-08-15 +2024-08-16 +2024-08-17 +2024-08-18 +2024-08-19 +2024-08-20 +2024-08-21 +2024-08-22 +2024-08-23 +2024-08-24 +2024-08-25 +2024-08-26 +2024-08-27 +2024-08-28 +2024-08-29 +2024-08-30 +2024-08-31 +2024-09-01 +2024-09-02 +2024-09-03 2024-09-04 2024-09-05 2024-09-06 @@ -131,54 +167,51 @@ const dates = `2024-09-03 2025-01-08 2025-01-09 2025-01-10 -2025-01-11` +2025-01-11 +2025-01-12` 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 + let day = date.getDate() + let month = date.getMonth() + 1 + let year = date.getFullYear() - // Add leading zero to day and month if needed - day = day < 10 ? '0' + day : day; - month = month < 10 ? '0' + month : month; + day = day < 10 ? '0' + day : day + month = month < 10 ? '0' + month : month - // Return the formatted date - return `${day}-${month}-${year}`; + return `${day}-${month}-${year}` } const wait = async function() { await new Promise((res) => { setTimeout(() => { - res(); - }, 60000); + res() + }, 125000) }) - } db.serialize(async () => { - // db.run("CREATE TABLE assets (asset TEXT, price VALUE, date DATE)"); - - const params = dates.split('\n'); + const params = dates.split('\n') for(i in params) { if(i % 5 == 0) { - await wait(); + await wait() } + const param = params[i] - const stmt = db.prepare("INSERT INTO assets VALUES (?, ?, ?)") const date = new Date(param) - const formattedDate= formatDate(date); + 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); + + try { + const stmt = db.prepare("INSERT INTO assets VALUES (?, ?, ?)") + const price = Number(data.market_data.current_price.rub) + stmt.run("ETH", price, date) + stmt.finalize() + console.log(param) + } catch { + console.log(data) + break + } } - - - db.each("SELECT * FROM assets", (err, row) => { - console.log(row); - }); -}); +}) diff --git a/package-lock.json b/repl/package-lock.json similarity index 100% rename from package-lock.json rename to repl/package-lock.json diff --git a/package.json b/repl/package.json similarity index 100% rename from package.json rename to repl/package.json diff --git a/repl/select.js b/repl/select.js new file mode 100644 index 0000000..dc70d2f --- /dev/null +++ b/repl/select.js @@ -0,0 +1,10 @@ +const sqlite3 = require('sqlite3').verbose() +const db = new sqlite3.Database('../db') + +db.serialize(async () => { + db.each("SELECT * FROM assets", (err, row) => { + row.date = new Date(row.date).toISOString() + row.date = row.date.substring(0, row.date.length - 14) + console.log(row) + }) +})