49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import fs from 'fs/promises';
|
|
import _ from 'lodash';
|
|
|
|
import discogsService from './src/discogs';
|
|
|
|
async function start() {
|
|
const discogs = discogsService();
|
|
const wants = JSON.parse(await fs.readFile('./data/margh.wantlist.json', { encoding: 'utf8' }))
|
|
console.log('wants', wants.length);
|
|
|
|
|
|
const listings = await Promise.all(wants.map(async w => {
|
|
try {
|
|
const l = await discogs.listings(w.id)
|
|
return l;
|
|
} catch (e) {
|
|
// console.error(e);
|
|
return null;
|
|
}
|
|
}));
|
|
|
|
|
|
// once we have all the listings
|
|
// group by seller
|
|
|
|
return _
|
|
.chain(listings)
|
|
.filter(l => l)
|
|
.reduce((acc, g) => acc.concat(g), [])
|
|
.map(l => ({
|
|
id: l.id,
|
|
description: l.release.description,
|
|
seller_id: l.seller.id,
|
|
seller_name: l.seller.username,
|
|
}))
|
|
.groupBy(l => l.seller_id)
|
|
.sortBy(s => s.length)
|
|
.reverse()
|
|
.head()
|
|
.value();
|
|
}
|
|
|
|
start()
|
|
.then(r => console.log(r))
|
|
.catch(e => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|