|
1 | 1 | // This can be run with `npx tsx scrape-neo-images.ts` |
2 | 2 | import * as cheerio from "cheerio"; |
3 | 3 | import * as fs from "fs"; |
4 | | -import * as path from "path"; |
| 4 | +import path, { dirname } from "path"; |
| 5 | +import { fileURLToPath } from "url"; |
5 | 6 | import { kNeoDatasetConfigs } from "../src/models/neo-dataset-configs.js"; |
6 | 7 | import { NeoImageInfo, ScrapedNeoDatasetInfo, ScrapedNeoDatasetMap } from "../src/models/neo-types.js"; |
7 | 8 |
|
| 9 | +const __filename = fileURLToPath(import.meta.url); |
| 10 | +const __dirname = dirname(__filename); |
| 11 | + |
8 | 12 | async function fetchHtml(url: string): Promise<string> { |
| 13 | + // Delay to avoid overwhelming the server |
| 14 | + await new Promise(resolve => setTimeout(resolve, 500)); |
9 | 15 | const response = await fetch(url); |
10 | 16 | return await response.text(); |
11 | 17 | } |
@@ -85,9 +91,9 @@ async function main() { |
85 | 91 | // results.MOD_LSTD_CLIM_M = await processDataset("MOD_LSTD_CLIM_M"); |
86 | 92 |
|
87 | 93 | // Make sure the data directory exists |
88 | | - const dataDir = path.join(process.cwd(), "src", "data"); |
| 94 | + const dataDir = path.join(__dirname, "..", "src", "data"); |
89 | 95 | if (!fs.existsSync(dataDir)) { |
90 | | - fs.mkdirSync(dataDir); |
| 96 | + fs.mkdirSync(dataDir, { recursive: true }); |
91 | 97 | } |
92 | 98 |
|
93 | 99 | // Save results |
|
0 commit comments