Compare commits

..

6 commits

Author SHA1 Message Date
8ccd69de1b borrar locks viejos 2023-12-23 23:16:21 -03:00
70c19bcc1f compilar sitio para node 2023-12-23 22:45:20 -03:00
c004be4a31 saltearse volver a scrapear algo que ya existe 2023-12-23 21:30:30 -03:00
106dee13ac mostrar colores y nombres de supermercados 2023-12-23 21:13:06 -03:00
dac949cdd3 empezar a mostrar cosas en el sitio! 2023-12-23 21:05:47 -03:00
2fdd89b4f8 TODO 2023-12-23 20:43:53 -03:00
14 changed files with 349 additions and 2237 deletions

File diff suppressed because it is too large Load diff

View file

@ -11,12 +11,12 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"better-sqlite3": "^9.2.2", "drizzle-orm": "^0.29.1"
"drizzle-kit": "^0.20.7",
"drizzle-orm": "^0.29.1",
"tsx": "^4.7.0"
}, },
"devDependencies": { "devDependencies": {
"better-sqlite3": "^9.2.2",
"drizzle-kit": "^0.20.7",
"tsx": "^4.7.0",
"@types/better-sqlite3": "^7.6.8" "@types/better-sqlite3": "^7.6.8"
} }
} }

View file

@ -103,16 +103,13 @@ importers:
dayjs: dayjs:
specifier: ^1.11.10 specifier: ^1.11.10
version: 1.11.10 version: 1.11.10
db-datos:
specifier: workspace:^
version: link:../db-datos
drizzle-orm: drizzle-orm:
specifier: ^0.29.1 specifier: ^0.29.1
version: 0.29.1(@types/better-sqlite3@7.6.8)(better-sqlite3@9.2.2) version: 0.29.1(@types/better-sqlite3@7.6.8)(better-sqlite3@9.2.2)
devDependencies: devDependencies:
'@sveltejs/adapter-auto': '@sveltejs/adapter-node':
specifier: ^3.0.0 specifier: ^2.0.2
version: 3.0.1(@sveltejs/kit@2.0.6) version: 2.0.2(@sveltejs/kit@2.0.6)
'@sveltejs/kit': '@sveltejs/kit':
specifier: ^2.0.0 specifier: ^2.0.0
version: 2.0.6(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.10) version: 2.0.6(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.10)
@ -125,6 +122,9 @@ importers:
autoprefixer: autoprefixer:
specifier: ^10.4.16 specifier: ^10.4.16
version: 10.4.16(postcss@8.4.32) version: 10.4.16(postcss@8.4.32)
db-datos:
specifier: workspace:^
version: link:../db-datos
postcss: postcss:
specifier: ^8.4.32 specifier: ^8.4.32
version: 8.4.32 version: 8.4.32
@ -938,6 +938,70 @@ packages:
resolution: {integrity: sha512-2LuNTFBIO0m7kKIQvvPHN6UE63VjpmL9rnEEaOOaiSPbZK+zUOYIzBAWcED+3XYzhYsd/0mD57VdxAEqqV52CQ==} resolution: {integrity: sha512-2LuNTFBIO0m7kKIQvvPHN6UE63VjpmL9rnEEaOOaiSPbZK+zUOYIzBAWcED+3XYzhYsd/0mD57VdxAEqqV52CQ==}
dev: true dev: true
/@rollup/plugin-commonjs@25.0.7(rollup@4.9.1):
resolution: {integrity: sha512-nEvcR+LRjEjsaSsc4x3XZfCCvZIaSMenZu/OiwOKGN2UhQpAYI7ru7czFvyWbErlpoGjnSX3D5Ch5FcMA3kRWQ==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^2.68.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
dependencies:
'@rollup/pluginutils': 5.1.0(rollup@4.9.1)
commondir: 1.0.1
estree-walker: 2.0.2
glob: 8.1.0
is-reference: 1.2.1
magic-string: 0.30.5
rollup: 4.9.1
dev: true
/@rollup/plugin-json@6.1.0(rollup@4.9.1):
resolution: {integrity: sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
dependencies:
'@rollup/pluginutils': 5.1.0(rollup@4.9.1)
rollup: 4.9.1
dev: true
/@rollup/plugin-node-resolve@15.2.3(rollup@4.9.1):
resolution: {integrity: sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^2.78.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
dependencies:
'@rollup/pluginutils': 5.1.0(rollup@4.9.1)
'@types/resolve': 1.20.2
deepmerge: 4.3.1
is-builtin-module: 3.2.1
is-module: 1.0.0
resolve: 1.22.8
rollup: 4.9.1
dev: true
/@rollup/pluginutils@5.1.0(rollup@4.9.1):
resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==}
engines: {node: '>=14.0.0'}
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
dependencies:
'@types/estree': 1.0.5
estree-walker: 2.0.2
picomatch: 2.3.1
rollup: 4.9.1
dev: true
/@rollup/rollup-android-arm-eabi@4.9.1: /@rollup/rollup-android-arm-eabi@4.9.1:
resolution: {integrity: sha512-6vMdBZqtq1dVQ4CWdhFwhKZL6E4L1dV6jUjuBvsavvNJSppzi6dLBbuV+3+IyUREaj9ZFvQefnQm28v4OCXlig==} resolution: {integrity: sha512-6vMdBZqtq1dVQ4CWdhFwhKZL6E4L1dV6jUjuBvsavvNJSppzi6dLBbuV+3+IyUREaj9ZFvQefnQm28v4OCXlig==}
cpu: [arm] cpu: [arm]
@ -1042,13 +1106,16 @@ packages:
dev: true dev: true
optional: true optional: true
/@sveltejs/adapter-auto@3.0.1(@sveltejs/kit@2.0.6): /@sveltejs/adapter-node@2.0.2(@sveltejs/kit@2.0.6):
resolution: {integrity: sha512-OpilmvRN136lUgOa9F0zpSI6g+PouOmk+YvJQrB+/hAtllLghjjYuoyfUsrF7U6oJ52cxCtAJTPXgZdyyCffrQ==} resolution: {integrity: sha512-iboANjLIB7Af74+og5IEQVSPsIfaO+o9zldU/7ljCGCrBj0t2gQlINtuwUhjvwhLgw9vHgICYWWZFxLM2C0zrg==}
peerDependencies: peerDependencies:
'@sveltejs/kit': ^2.0.0 '@sveltejs/kit': ^2.0.0
dependencies: dependencies:
'@rollup/plugin-commonjs': 25.0.7(rollup@4.9.1)
'@rollup/plugin-json': 6.1.0(rollup@4.9.1)
'@rollup/plugin-node-resolve': 15.2.3(rollup@4.9.1)
'@sveltejs/kit': 2.0.6(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.10) '@sveltejs/kit': 2.0.6(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.10)
import-meta-resolve: 4.0.0 rollup: 4.9.1
dev: true dev: true
/@sveltejs/kit@2.0.6(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.10): /@sveltejs/kit@2.0.6(@sveltejs/vite-plugin-svelte@3.0.1)(svelte@4.2.8)(vite@5.0.10):
@ -1147,6 +1214,10 @@ packages:
resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==} resolution: {integrity: sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==}
dev: true dev: true
/@types/resolve@1.20.2:
resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==}
dev: true
/acorn-walk@8.3.1: /acorn-walk@8.3.1:
resolution: {integrity: sha512-TgUZgYvqZprrl7YldZNoa9OciCAyZR+Ejm9eXzKCmjsF5IKp/wgQ7Z/ZpjpGTIUPwrHQIcYeI8qDh4PsEwxMbw==} resolution: {integrity: sha512-TgUZgYvqZprrl7YldZNoa9OciCAyZR+Ejm9eXzKCmjsF5IKp/wgQ7Z/ZpjpGTIUPwrHQIcYeI8qDh4PsEwxMbw==}
engines: {node: '>=0.4.0'} engines: {node: '>=0.4.0'}
@ -1318,6 +1389,11 @@ packages:
ieee754: 1.2.1 ieee754: 1.2.1
dev: false dev: false
/builtin-modules@3.3.0:
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
engines: {node: '>=6'}
dev: true
/bun-types@1.0.18: /bun-types@1.0.18:
resolution: {integrity: sha512-1XZ7AxOF8oO8FZtw1xj006JAKxEjulK3dUhsktZVN95vXBlsf4NIjQxfistVdpt24v3H2I9BwHp+UU+gXSSpAw==} resolution: {integrity: sha512-1XZ7AxOF8oO8FZtw1xj006JAKxEjulK3dUhsktZVN95vXBlsf4NIjQxfistVdpt24v3H2I9BwHp+UU+gXSSpAw==}
dev: true dev: true
@ -1440,6 +1516,10 @@ packages:
engines: {node: ^12.20.0 || >=14} engines: {node: ^12.20.0 || >=14}
dev: false dev: false
/commondir@1.0.1:
resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==}
dev: true
/concat-map@0.0.1: /concat-map@0.0.1:
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
dev: true dev: true
@ -1892,6 +1972,10 @@ packages:
resolution: {integrity: sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==} resolution: {integrity: sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==}
dev: false dev: false
/estree-walker@2.0.2:
resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==}
dev: true
/estree-walker@3.0.3: /estree-walker@3.0.3:
resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==}
dependencies: dependencies:
@ -2053,7 +2137,6 @@ packages:
inherits: 2.0.4 inherits: 2.0.4
minimatch: 5.1.6 minimatch: 5.1.6
once: 1.4.0 once: 1.4.0
dev: false
/globalyzer@0.1.0: /globalyzer@0.1.0:
resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==} resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==}
@ -2114,10 +2197,6 @@ packages:
resolve-from: 4.0.0 resolve-from: 4.0.0
dev: true dev: true
/import-meta-resolve@4.0.0:
resolution: {integrity: sha512-okYUR7ZQPH+efeuMJGlq4f8ubUgO50kByRPyt/Cy1Io4PSRsPjxME+YlVaCOx+NIToW7hCsZNFJyTPFFKepRSA==}
dev: true
/inflight@1.0.6: /inflight@1.0.6:
resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==}
dependencies: dependencies:
@ -2137,6 +2216,13 @@ packages:
dependencies: dependencies:
binary-extensions: 2.2.0 binary-extensions: 2.2.0
/is-builtin-module@3.2.1:
resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==}
engines: {node: '>=6'}
dependencies:
builtin-modules: 3.3.0
dev: true
/is-core-module@2.13.1: /is-core-module@2.13.1:
resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==} resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==}
dependencies: dependencies:
@ -2157,6 +2243,10 @@ packages:
dependencies: dependencies:
is-extglob: 2.1.1 is-extglob: 2.1.1
/is-module@1.0.0:
resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==}
dev: true
/is-number@7.0.0: /is-number@7.0.0:
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
engines: {node: '>=0.12.0'} engines: {node: '>=0.12.0'}
@ -2165,6 +2255,12 @@ packages:
resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==} resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==}
dev: false dev: false
/is-reference@1.2.1:
resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==}
dependencies:
'@types/estree': 1.0.5
dev: true
/is-reference@3.0.2: /is-reference@3.0.2:
resolution: {integrity: sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==} resolution: {integrity: sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==}
dependencies: dependencies:
@ -2356,7 +2452,6 @@ packages:
engines: {node: '>=10'} engines: {node: '>=10'}
dependencies: dependencies:
brace-expansion: 2.0.1 brace-expansion: 2.0.1
dev: false
/minimatch@7.4.6: /minimatch@7.4.6:
resolution: {integrity: sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw==} resolution: {integrity: sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw==}

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,7 @@ import { getDiaProduct } from "./dia.js";
import { getCotoProduct } from "./coto.js"; import { getCotoProduct } from "./coto.js";
import { join } from "path"; import { join } from "path";
import pMap from "p-map"; import pMap from "p-map";
import { and, eq, sql } from "drizzle-orm";
const DEBUG = false; const DEBUG = false;
const PARSER_VERSION = 1; const PARSER_VERSION = 1;
@ -22,6 +23,17 @@ sqlite.run(`
pragma journal_mode = WAL; pragma journal_mode = WAL;
PRAGMA synchronous = NORMAL; PRAGMA synchronous = NORMAL;
`); `);
const getPrevPrecio = db
.select({ id: schema.precios.id })
.from(schema.precios)
.where(
and(
eq(schema.precios.warcRecordId, sql.placeholder("warcRecordId")),
eq(schema.precios.parserVersion, PARSER_VERSION)
)
)
.limit(1)
.prepare();
let progress = { done: 0, errors: 0 }; let progress = { done: 0, errors: 0 };
await pMap(process.argv.slice(2), (path) => parseWarc(path), { await pMap(process.argv.slice(2), (path) => parseWarc(path), {
@ -49,6 +61,15 @@ async function parseWarc(path: string) {
for await (const record of parser) { for await (const record of parser) {
if (record.warcType === "response") { if (record.warcType === "response") {
if (!record.warcTargetURI) continue; if (!record.warcTargetURI) continue;
const warcRecordId = record.warcHeader("WARC-Record-ID");
if (!warcRecordId) throw new Error("No tiene WARC-Record-ID");
if (getPrevPrecio.get({ warcRecordId })) {
console.debug(`skipped ${warcRecordId}`);
continue;
}
// TODO: sobreescribir si existe el mismo record-id pero con version mas bajo?
const html = await record.contentText(); const html = await record.contentText();
const url = new URL(record.warcTargetURI); const url = new URL(record.warcTargetURI);
@ -66,7 +87,7 @@ async function parseWarc(path: string) {
...ish, ...ish,
fetchedAt: new Date(record.warcDate!), fetchedAt: new Date(record.warcDate!),
url: record.warcTargetURI, url: record.warcTargetURI,
warcRecordId: record.warcHeader("WARC-Record-ID"), warcRecordId,
parserVersion: PARSER_VERSION, parserVersion: PARSER_VERSION,
}; };

View file

@ -12,22 +12,30 @@
"format": "prettier --write ." "format": "prettier --write ."
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0", "@sveltejs/adapter-node": "^2.0.2",
"@sveltejs/kit": "^2.0.0", "@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/better-sqlite3": "^7.6.8",
"autoprefixer": "^10.4.16", "autoprefixer": "^10.4.16",
"db-datos": "workspace:^",
"postcss": "^8.4.32", "postcss": "^8.4.32",
"postcss-load-config": "^5.0.2", "postcss-load-config": "^5.0.2",
"prettier": "^3.1.1", "prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2", "prettier-plugin-svelte": "^3.1.2",
"prettier-plugin-tailwindcss": "^0.5.9", "prettier-plugin-tailwindcss": "^0.5.9",
"svelte": "^4.2.7", "svelte": "^4.2.7",
"svelte-adapter-bun": "^0.5.1",
"svelte-check": "^3.6.0", "svelte-check": "^3.6.0",
"tailwindcss": "^3.3.6", "tailwindcss": "^3.3.6",
"tslib": "^2.4.1", "tslib": "^2.4.1",
"typescript": "^5.0.0", "typescript": "^5.0.0",
"vite": "^5.0.3" "vite": "^5.0.3"
}, },
"type": "module" "type": "module",
"dependencies": {
"better-sqlite3": "^9.2.2",
"chart.js": "^4.4.1",
"chartjs-adapter-dayjs-4": "^1.0.4",
"dayjs": "^1.11.10",
"drizzle-orm": "^0.29.1"
}
} }

View file

@ -0,0 +1,9 @@
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "db-datos/schema.js";
import { env } from "$env/dynamic/private";
const sqlite = new Database(env.DB_PATH ?? "../scraper/sqlite.db");
export const db = drizzle(sqlite, { schema });
export * as schema from "db-datos/schema.js";

View file

@ -0,0 +1,18 @@
import { error } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
import { db, schema } from "$lib/server/db";
import { ilike, like, sql } from "drizzle-orm";
export const load: PageServerLoad = async ({ params }) => {
const q = db
.select({ ean: schema.precios.ean })
.from(schema.precios)
.where(
like(schema.precios.url, `https://diaonline.supermercadosdia.com.ar%`),
)
.groupBy(schema.precios.ean)
.orderBy(sql`random()`)
.limit(150);
const precios = await q;
return { precios };
};

View file

@ -1,4 +1,17 @@
<h1>Welcome to SvelteKit</h1> <script lang="ts">
<p> import type { PageData } from "./$types";
Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation
</p> export let data: PageData;
</script>
<h1 class="text-xl">WIP</h1>
<ul>
{#each data.precios as product}
<li>
<a href={`/ean/${product.ean}`}>
{product.ean}
</a>
</li>
{/each}
</ul>

View file

@ -0,0 +1,13 @@
import { error } from "@sveltejs/kit";
import { eq } from "drizzle-orm";
import type { PageServerLoad } from "./$types";
import { db, schema } from "$lib/server/db";
export const load: PageServerLoad = async ({ params }) => {
const precios = await db.query.precios.findMany({
where: eq(schema.precios.ean, params.ean),
});
if (precios.length === 0) return error(404, "Not Found");
return { precios };
};

View file

@ -0,0 +1,23 @@
<script lang="ts">
import type { PageData } from "./$types";
import Chart from "./Chart.svelte";
export let data: PageData;
</script>
<ul>
{#each data.precios as precio}
<li>
{precio.url}
:
{#if precio.precioCentavos}
{precio.precioCentavos / 100}
{:else}
{precio.inStock}
{/if}
({precio.fetchedAt})
</li>
{/each}
</ul>
<Chart precios={data.precios} />

View file

@ -0,0 +1,72 @@
<script lang="ts">
import type { Precio } from "db-datos/schema";
// import dayjs from "dayjs";
import ChartJs from "./ChartJs.svelte";
export let precios: Precio[];
enum Supermercado {
Dia = "Dia",
Carrefour = "Carrefour",
Coto = "Coto",
}
const hosts: { [host: string]: Supermercado } = {
"diaonline.supermercadosdia.com.ar": Supermercado.Dia,
"www.carrefour.com.ar": Supermercado.Carrefour,
"www.cotodigital3.com.ar": Supermercado.Coto,
};
const colorBySupermercado: { [supermercado in Supermercado]: string } = {
[Supermercado.Dia]: "#d52b1e",
[Supermercado.Carrefour]: "#19549d",
[Supermercado.Coto]: "#e20025",
};
$: datasets = precios
.map((p) => new URL(p.url!).hostname)
.filter(onlyUnique)
.map((host) => {
const supermercado = hosts[host];
const ps = precios
.filter((p) => new URL(p.url!).hostname === host)
.filter(
(p): p is Precio & { precioCentavos: number } =>
p.precioCentavos !== null,
);
return {
label: supermercado,
data: [
...ps.map((p) => ({
x: p.fetchedAt,
y: p.precioCentavos / 100,
})),
// lie
// ...ps.map((p) => ({
// x: dayjs(p.fetchedAt).add(14, "day").toDate(),
// y: p.precioCentavos / 100 + 100,
// })),
],
fill: false,
borderColor: colorBySupermercado[supermercado],
tension: 0.1,
};
});
function onlyUnique(value: any, index: any, self: string | any[]) {
return self.indexOf(value) === index;
}
</script>
<div class="h-[300px] w-full min-w-[500px]">
<ChartJs
type="line"
data={{ datasets }}
options={{
responsive: true,
scales: {
x: { type: "time" },
},
}}
/>
</div>

View file

@ -0,0 +1,48 @@
<script lang="ts">
import {
Chart,
LineController,
type ChartData,
type ChartOptions,
type ChartType,
type Point,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Filler,
TimeScale,
Tooltip,
Legend,
} from "chart.js";
import "chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm";
import { onMount } from "svelte";
Chart.register(
LineController,
LineElement,
CategoryScale,
LinearScale,
TimeScale,
PointElement,
Filler,
Tooltip,
Legend,
);
export let type: ChartType;
export let data: ChartData<typeof type, { x: Date; y: number }[]>;
export let options: ChartOptions<typeof type> = {};
let canvasEl: HTMLCanvasElement;
onMount(() => {
const chart = new Chart(canvasEl, {
type,
data,
options,
});
return () => chart.destroy();
});
</script>
<canvas bind:this={canvasEl} />

View file

@ -1,17 +1,12 @@
// import adapter from "@sveltejs/adapter-auto"; import adapter from "@sveltejs/adapter-node";
import adapter from "svelte-adapter-bun"; // import adapter from "svelte-adapter-bun";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: [vitePreprocess({})], preprocess: [vitePreprocess({})],
kit: { kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter(), adapter: adapter(),
}, },
}; };