~shreyasminocha/leetcode-problem-scrape

f4c3ccd60d368fb23a1ee8ae1dc4957fa1b92d44 — Shreyas Minocha 4 months ago 217255c
Fix dump directory creation

…I think. This was a while ago.
1 files changed, 14 insertions(+), 2 deletions(-)

M index.js
M index.js => index.js +14 -2
@@ 7,10 7,22 @@ const dumpPath = process.argv[2];
let response = await got('https://leetcode.com/api/problems/all/').json();
const problems = response.stat_status_pairs;

await fs.mkdir(path.join(dumpPath, 'problems'));
const problemsFolder = path.join(dumpPath, 'problems');

try {
	await fs.access(problemsFolder);
} catch (error) {
	await fs.mkdir(problemsFolder);
}

for (const problem of problems) {
	const slug = problem.stat.question__title_slug;
	const problemPath = path.join(dumpPath, 'problems', `${slug}.json`);

	try {
		await fs.access(problemPath);
		continue;
	} catch (error) {}

	response = await got.post('https://leetcode.com/graphql', {
		json: {


@@ 22,5 34,5 @@ for (const problem of problems) {

	const { question } = response.data;

	fs.writeFile(path.join(dumpPath, 'problems', `${slug}.json`), JSON.stringify(question));
	fs.writeFile(problemPath, JSON.stringify(question));
}