Portage complet PHP/Bash vers Node.js (Fastify + worker_threads)
This commit is contained in:
36
cron/imdbRatings.js
Normal file
36
cron/imdbRatings.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { createWriteStream } from 'node:fs';
|
||||
import { rename } from 'node:fs/promises';
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
import { createGunzip } from 'node:zlib';
|
||||
import { Readable } from 'node:stream';
|
||||
import { join } from 'node:path';
|
||||
import { ROOT, IMDB_DATASETS_BASE, IMDB_RATINGS } from '../config.js';
|
||||
|
||||
const FILE = 'title.ratings.tsv';
|
||||
|
||||
export async function syncImdbRatings() {
|
||||
const url = `${IMDB_DATASETS_BASE}/${FILE}.gz`;
|
||||
const tmpPath = join(ROOT, `${FILE}.tmp`);
|
||||
|
||||
console.log(`Downloading: "${url}"`);
|
||||
const res = await fetch(url);
|
||||
if (!res.ok || !res.body) {
|
||||
throw new Error(`Failed to fetch ${url}: HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
await pipeline(
|
||||
Readable.fromWeb(res.body),
|
||||
createGunzip(),
|
||||
createWriteStream(tmpPath),
|
||||
);
|
||||
|
||||
await rename(tmpPath, IMDB_RATINGS);
|
||||
console.log(`Wrote ${IMDB_RATINGS}`);
|
||||
}
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
syncImdbRatings().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user