Files
crates/index.ts
T
2022-07-25 01:38:49 +10:00

44 lines
1.1 KiB
TypeScript

import fs from 'fs/promises';
import _ from 'lodash';
import Promise from 'bluebird';
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);
return Promise.map(wants, async w => {
try {
const l = await discogs.listings(w.id)
return l;
} catch (e) {
// console.error(e);
return null;
}
})
.then(listings => _
.chain(listings)
.filter(l => l)
.flatten()
.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);
});