Compare commits

..

No commits in common. "88e3aef8adb402e62dccbe10a57170eeb8609120" and "c75f8c335cc5b1c0b42bf03265b6c2053fb62b4f" have entirely different histories.

3 changed files with 6 additions and 9 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -50,13 +50,13 @@ supermercados.forEach(downloadList);
async function downloadList(supermercado: Supermercado) { async function downloadList(supermercado: Supermercado) {
const listPath = resolve( const listPath = resolve(
join(process.env.LISTS_DIR ?? "../data", `${supermercado}.txt`), join(process.env.LISTS_DIR ?? "../data", `${supermercado}.txt`)
); );
const date = new Date(); const date = new Date();
const ctxPath = await mkdtemp(join(tmpdir(), "preciazo-scraper-wget-")); const ctxPath = await mkdtemp(join(tmpdir(), "preciazo-scraper-wget-"));
const zstdWarcName = `${supermercado}-${format( const zstdWarcName = `${supermercado}-${format(
date, date,
"yyyy-MM-dd-HH:mm", "yyyy-MM-dd-HH:mm"
)}.warc.zst`; )}.warc.zst`;
const zstdWarcPath = join(ctxPath, zstdWarcName); const zstdWarcPath = join(ctxPath, zstdWarcName);
const subproc = Bun.spawn({ const subproc = Bun.spawn({
@ -100,8 +100,6 @@ async function downloadList(supermercado: Supermercado) {
inform(`Falló subir ${zstdWarcName} a S3; ${error}`); inform(`Falló subir ${zstdWarcName} a S3; ${error}`);
console.error(error); console.error(error);
} }
// TODO: borrar archivos temporales
} }
async function scrapAndInform({ async function scrapAndInform({
@ -122,7 +120,7 @@ async function scrapAndInform({
inform( inform(
`Procesado ${zstdWarcName} (${progress.done} ok, ${ `Procesado ${zstdWarcName} (${progress.done} ok, ${
progress.errors.length progress.errors.length
} errores) (tardó ${formatMs(took)})`, } errores) (tardó ${formatMs(took)})`
); );
} else { } else {
inform(`Algo falló en ${zstdWarcName}`); inform(`Algo falló en ${zstdWarcName}`);
@ -159,7 +157,7 @@ function recompress(inputPath: string, outputPath: string) {
["-T0", "-15", "--long", "-o", outputPath], ["-T0", "-15", "--long", "-o", outputPath],
{ {
stdio: ["pipe", null, null], stdio: ["pipe", null, null],
}, }
); );
// @ts-expect-error a los types de bun no le gusta???? // @ts-expect-error a los types de bun no le gusta????
decompressor.stdout.pipe(compressor.stdin); decompressor.stdout.pipe(compressor.stdin);
@ -215,7 +213,7 @@ async function sendTelegramMsg(text: string) {
if (!process.env.TELEGRAM_BOT_TOKEN || !process.env.TELEGRAM_BOT_CHAT_ID) if (!process.env.TELEGRAM_BOT_TOKEN || !process.env.TELEGRAM_BOT_CHAT_ID)
return; return;
const url = new URL( const url = new URL(
`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`
); );
url.searchParams.set("chat_id", process.env.TELEGRAM_BOT_CHAT_ID); url.searchParams.set("chat_id", process.env.TELEGRAM_BOT_CHAT_ID);
url.searchParams.set("text", text); url.searchParams.set("text", text);

View file

@ -10,8 +10,7 @@ export const load: PageServerLoad = async ({ params }) => {
.from(precios) .from(precios)
.where(eq(precios.ean, params.ean)) .where(eq(precios.ean, params.ean))
.groupBy(precios.warcRecordId) .groupBy(precios.warcRecordId)
.having(max(precios.parserVersion)) .having(max(precios.parserVersion));
.orderBy(precios.fetchedAt);
const res = await q; const res = await q;
if (res.length === 0) return error(404, "Not Found"); if (res.length === 0) return error(404, "Not Found");