we function
This commit is contained in:
1 parent
76dc840cf7
commit
245616acd4
4 files changed
+19
-12
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
import discogsService from './src/discogs';
|
import discogsService from './src/discogs';
|
||||||
|
|
||||||
@@ -8,8 +9,7 @@ async function start() {
|
|||||||
const wants = JSON.parse(await fs.readFile('./data/margh.wantlist.json', { encoding: 'utf8' }))
|
const wants = JSON.parse(await fs.readFile('./data/margh.wantlist.json', { encoding: 'utf8' }))
|
||||||
console.log('wants', wants.length);
|
console.log('wants', wants.length);
|
||||||
|
|
||||||
|
return Promise.map(wants, async w => {
|
||||||
const listings = await Promise.all(wants.map(async w => {
|
|
||||||
try {
|
try {
|
||||||
const l = await discogs.listings(w.id)
|
const l = await discogs.listings(w.id)
|
||||||
return l;
|
return l;
|
||||||
@@ -17,16 +17,11 @@ async function start() {
|
|||||||
// console.error(e);
|
// console.error(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}));
|
})
|
||||||
|
.then(listings => _
|
||||||
|
|
||||||
// once we have all the listings
|
|
||||||
// group by seller
|
|
||||||
|
|
||||||
return _
|
|
||||||
.chain(listings)
|
.chain(listings)
|
||||||
.filter(l => l)
|
.filter(l => l)
|
||||||
.reduce((acc, g) => acc.concat(g), [])
|
.flatten()
|
||||||
.map(l => ({
|
.map(l => ({
|
||||||
id: l.id,
|
id: l.id,
|
||||||
description: l.release.description,
|
description: l.release.description,
|
||||||
@@ -37,7 +32,7 @@ async function start() {
|
|||||||
.sortBy(s => s.length)
|
.sortBy(s => s.length)
|
||||||
.reverse()
|
.reverse()
|
||||||
.head()
|
.head()
|
||||||
.value();
|
.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
start()
|
start()
|
||||||
|
|||||||
Generated
+11
@@ -10,6 +10,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
|
"bluebird": "^3.7.2",
|
||||||
"bunyan": "^1.8.15",
|
"bunyan": "^1.8.15",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"knex": "^2.2.0",
|
"knex": "^2.2.0",
|
||||||
@@ -188,6 +189,11 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/bluebird": {
|
||||||
|
"version": "3.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
|
||||||
|
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
|
||||||
|
},
|
||||||
"node_modules/body-parser": {
|
"node_modules/body-parser": {
|
||||||
"version": "1.20.0",
|
"version": "1.20.0",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz",
|
||||||
@@ -2041,6 +2047,11 @@
|
|||||||
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
|
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"bluebird": {
|
||||||
|
"version": "3.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
|
||||||
|
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
|
||||||
|
},
|
||||||
"body-parser": {
|
"body-parser": {
|
||||||
"version": "1.20.0",
|
"version": "1.20.0",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.0.tgz",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
|
"bluebird": "^3.7.2",
|
||||||
"bunyan": "^1.8.15",
|
"bunyan": "^1.8.15",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"knex": "^2.2.0",
|
"knex": "^2.2.0",
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ export default function discogs() {
|
|||||||
// console.log('cached', id);
|
// console.log('cached', id);
|
||||||
return JSON.parse(await fs.readFile(path, { encoding: 'utf8' }));
|
return JSON.parse(await fs.readFile(path, { encoding: 'utf8' }));
|
||||||
}
|
}
|
||||||
// console.log('fetching', id);
|
console.log('fetching', id);
|
||||||
const res = await api.get(`${apiBase}/marketplace/listings/${id}`);
|
const res = await api.get(`${apiBase}/marketplace/listings/${id}`);
|
||||||
await fs.writeFile(path, JSON.stringify(res.data, null, 4));
|
await fs.writeFile(path, JSON.stringify(res.data, null, 4));
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|||||||
Reference in new issue
Block a user