@@ 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));
}