julien-c HF Staff commited on
Commit
07af8dc
·
verified ·
1 Parent(s): 9e03941

Update split-urls.js

Browse files
Files changed (1) hide show
  1. split-urls.js +15 -13
split-urls.js CHANGED
@@ -1,27 +1,29 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const readline = require('readline');
4
 
5
  async function processUrls() {
6
- const inputFile = path.join(__dirname, '__urls.csv');
7
-
8
  const fileStream = fs.createReadStream(inputFile);
9
  const rl = readline.createInterface({
10
  input: fileStream,
11
- crlfDelay: Infinity
12
  });
13
 
14
  for await (const line of rl) {
15
- if (!line.trim()) continue;
16
-
17
- const parts = line.split(',');
 
 
18
  const prefix = parts[0].substring(0, 3);
19
- const outputFile = path.join(__dirname, `${prefix}.csv`);
20
-
21
- fs.appendFileSync(outputFile, line + '\n');
22
  }
23
 
24
- console.log('Done processing URLs');
25
  }
26
 
27
  processUrls().catch(console.error);
 
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const readline = require("readline");
4
 
5
  async function processUrls() {
6
+ const inputFile = path.join(__dirname, "__urls.csv");
7
+
8
  const fileStream = fs.createReadStream(inputFile);
9
  const rl = readline.createInterface({
10
  input: fileStream,
11
+ crlfDelay: Infinity,
12
  });
13
 
14
  for await (const line of rl) {
15
+ if (!line.trim()) {
16
+ continue;
17
+ }
18
+
19
+ const parts = line.split(",");
20
  const prefix = parts[0].substring(0, 3);
21
+ const outputFile = path.join(__dirname, "split", `${prefix}.csv`);
22
+
23
+ fs.appendFileSync(outputFile, line + "\n");
24
  }
25
 
26
+ console.log("Done processing URLs");
27
  }
28
 
29
  processUrls().catch(console.error);