Adding loop on each database row

main
Félix MIELCAREK 1 year ago
parent 17d3c0d12f
commit cc7d383d49

@ -1,13 +1,18 @@
//#region REQUIRE //#region REQUIRE
const axios = require('axios'); const axios = require('axios');
const fs = require('node:fs'); const { Client } = require('pg');
const path = require('path');
//#endregion //#endregion
//#region CONSTANTS //#region CONSTANTS
const commonDir = path.join(__dirname, '../common');
const spotifyRequestsLimit = 50; const spotifyRequestsLimit = 50;
const thresholdLove = 0.6; const thresholdLove = 0.6;
const client = new Client({
user: process.env.DB_USER,
host: 'localhost',
database: 'bigbrother',
password: process.env.DB_PASSWORD,
port: 5432
});
//#endregion //#endregion
//#region STRUCTURE //#region STRUCTURE
@ -149,13 +154,15 @@ function stepBeggining(step) {
//#region MAIN //#region MAIN
async function main() { async function main() {
var albums = {}; try {
await client.connect();
const query = 'SELECT accesstoken FROM public.users';
const result = await client.query(query);
var accessToken; result.rows.forEach(async (row) => {
try { accessToken = fs.readFileSync(commonDir + '/spotify_access_token', 'utf8') } var albums = {};
catch (err) { console.error(err) } var accessToken = row.accesstoken
// ======================================================
const step1 = "Get liked tracks"; const step1 = "Get liked tracks";
const step2 = "Apply treshold algorithm"; const step2 = "Apply treshold algorithm";
const step3 = "Remove saved tracks from saved albums"; const step3 = "Remove saved tracks from saved albums";
@ -172,6 +179,8 @@ async function main() {
await removeTracksAlgorithm(albums, accessToken); await removeTracksAlgorithm(albums, accessToken);
stepSuccess(step3); stepSuccess(step3);
} catch (error) { } } catch (error) { }
});
} catch (error) { console.error('Error executing query:', error) } finally { await client.end() }
} }
//#endregion //#endregion

Loading…
Cancel
Save