Compare commits
No commits in common. "f76d9a179a494234cbe6ad6056e8287d23260a6c" and "3d53a6ced5175f27c0d84bc282a8bae7db91d96f" have entirely different histories.
f76d9a179a
...
3d53a6ced5
|
@ -1 +1 @@
|
||||||
*/node_modules
|
node_modules
|
||||||
|
|
25
api/index.js
25
api/index.js
|
@ -1,25 +0,0 @@
|
||||||
import fetch from 'node-fetch'
|
|
||||||
import express from 'express'
|
|
||||||
const app = express()
|
|
||||||
const db = '../db'
|
|
||||||
const port = 3102
|
|
||||||
|
|
||||||
app.get('/ETH/:date', async (req, res) => {
|
|
||||||
const response = await fetch(`https://api.coingecko.com/api/v3/coins/ethereum/history?date=${req.params.date}`)
|
|
||||||
const data = await response.json()
|
|
||||||
res.send(data.market_data.current_price.rub.toString())
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/TRX/:date', async (req, res) => {
|
|
||||||
const response = await fetch(`https://api.coingecko.com/api/v3/coins/tron/history?date=${req.params.date}`)
|
|
||||||
const data = await response.json()
|
|
||||||
res.send(data.market_data.current_price.rub.toString())
|
|
||||||
})
|
|
||||||
|
|
||||||
app.listen(port, () => {
|
|
||||||
console.log(`App listening on port ${port}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
process
|
|
||||||
.on('unhandledRejection', () => {})
|
|
||||||
.on('uncaughtException', () => {})
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"name": "assets",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"express": "^4.21.2",
|
|
||||||
"node-fetch": "^3.3.2",
|
|
||||||
"nodemon": "^3.1.9"
|
|
||||||
},
|
|
||||||
"type": "module"
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,43 +1,7 @@
|
||||||
const sqlite3 = require('sqlite3').verbose()
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
const db = new sqlite3.Database('../db')
|
const db = new sqlite3.Database('./db');
|
||||||
|
|
||||||
const dates =
|
const dates = `2024-09-03
|
||||||
`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-04
|
||||||
2024-09-05
|
2024-09-05
|
||||||
2024-09-06
|
2024-09-06
|
||||||
|
@ -167,51 +131,54 @@ const dates =
|
||||||
2025-01-08
|
2025-01-08
|
||||||
2025-01-09
|
2025-01-09
|
||||||
2025-01-10
|
2025-01-10
|
||||||
2025-01-11
|
2025-01-11`
|
||||||
2025-01-12`
|
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
let day = date.getDate()
|
// Extract the day, month, and year from the date
|
||||||
let month = date.getMonth() + 1
|
let day = date.getDate(); // Get the day
|
||||||
let year = date.getFullYear()
|
let month = date.getMonth() + 1; // Get the month (0-based index, so add 1)
|
||||||
|
let year = date.getFullYear(); // Get the full year
|
||||||
|
|
||||||
day = day < 10 ? '0' + day : day
|
// Add leading zero to day and month if needed
|
||||||
month = month < 10 ? '0' + month : month
|
day = day < 10 ? '0' + day : day;
|
||||||
|
month = month < 10 ? '0' + month : month;
|
||||||
|
|
||||||
return `${day}-${month}-${year}`
|
// Return the formatted date
|
||||||
|
return `${day}-${month}-${year}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wait = async function() {
|
const wait = async function() {
|
||||||
await new Promise((res) => {
|
await new Promise((res) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
res()
|
res();
|
||||||
}, 125000)
|
}, 60000);
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db.serialize(async () => {
|
db.serialize(async () => {
|
||||||
const params = dates.split('\n')
|
// db.run("CREATE TABLE assets (asset TEXT, price VALUE, date DATE)");
|
||||||
|
|
||||||
|
const params = dates.split('\n');
|
||||||
|
|
||||||
for(i in params) {
|
for(i in params) {
|
||||||
if(i % 5 == 0) {
|
if(i % 5 == 0) {
|
||||||
await wait()
|
await wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
const param = params[i]
|
const param = params[i]
|
||||||
const date = new Date(param)
|
|
||||||
const formattedDate= formatDate(date)
|
|
||||||
const response = await fetch(`https://api.coingecko.com/api/v3/coins/tron/history?date=${formattedDate}`)
|
|
||||||
const data = await response.json()
|
|
||||||
|
|
||||||
try {
|
|
||||||
const stmt = db.prepare("INSERT INTO assets VALUES (?, ?, ?)")
|
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)
|
const price = Number(data.market_data.current_price.rub)
|
||||||
stmt.run("TRX", price, date)
|
stmt.run("ETH", price, date)
|
||||||
stmt.finalize()
|
stmt.finalize();
|
||||||
console.log(param)
|
console.log(param);
|
||||||
} catch {
|
|
||||||
console.log(data)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
db.each("SELECT * FROM assets", (err, row) => {
|
||||||
|
console.log(row);
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +0,0 @@
|
||||||
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)")
|
|
||||||
})
|
|
|
@ -1,10 +0,0 @@
|
||||||
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)
|
|
||||||
})
|
|
||||||
})
|
|
Loading…
Reference in New Issue