This commit is contained in:
cheney 2026-04-19 08:42:20 +08:00
parent 2820adfdd3
commit f9e1471487
3 changed files with 132 additions and 6 deletions

107
package-lock.json generated
View File

@ -9,8 +9,10 @@
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@prisma/adapter-mariadb": "^7.7.0",
"@prisma/client": "^7.7.0", "@prisma/client": "^7.7.0",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"mariadb": "^3.5.2",
"marked": "^17.0.6", "marked": "^17.0.6",
"next": "^14.2.3", "next": "^14.2.3",
"prisma": "^7.7.0", "prisma": "^7.7.0",
@ -219,6 +221,59 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/@prisma/adapter-mariadb": {
"version": "7.7.0",
"resolved": "https://registry.npmmirror.com/@prisma/adapter-mariadb/-/adapter-mariadb-7.7.0.tgz",
"integrity": "sha512-BlugprCUNFGelP7t0uQEHkC5ZcNmgUxWi6xpkjWKUS9gESGBDF3mNdYFqRc2zS9w7pC83gpNxSY51A7gCY2HdA==",
"license": "Apache-2.0",
"dependencies": {
"@prisma/driver-adapter-utils": "7.7.0",
"mariadb": "3.4.5"
}
},
"node_modules/@prisma/adapter-mariadb/node_modules/@types/node": {
"version": "24.12.2",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-24.12.2.tgz",
"integrity": "sha512-A1sre26ke7HDIuY/M23nd9gfB+nrmhtYyMINbjI1zHJxYteKR6qSMX56FsmjMcDb3SMcjJg5BiRRgOCC/yBD0g==",
"license": "MIT",
"dependencies": {
"undici-types": "~7.16.0"
}
},
"node_modules/@prisma/adapter-mariadb/node_modules/iconv-lite": {
"version": "0.6.3",
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/@prisma/adapter-mariadb/node_modules/mariadb": {
"version": "3.4.5",
"resolved": "https://registry.npmmirror.com/mariadb/-/mariadb-3.4.5.tgz",
"integrity": "sha512-gThTYkhIS5rRqkVr+Y0cIdzr+GRqJ9sA2Q34e0yzmyhMCwyApf3OKAC1jnF23aSlIOqJuyaUFUcj7O1qZslmmQ==",
"license": "LGPL-2.1-or-later",
"dependencies": {
"@types/geojson": "^7946.0.16",
"@types/node": "^24.0.13",
"denque": "^2.1.0",
"iconv-lite": "^0.6.3",
"lru-cache": "^10.4.3"
},
"engines": {
"node": ">= 14"
}
},
"node_modules/@prisma/adapter-mariadb/node_modules/undici-types": {
"version": "7.16.0",
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-7.16.0.tgz",
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
"license": "MIT"
},
"node_modules/@prisma/client": { "node_modules/@prisma/client": {
"version": "7.7.0", "version": "7.7.0",
"resolved": "https://registry.npmmirror.com/@prisma/client/-/client-7.7.0.tgz", "resolved": "https://registry.npmmirror.com/@prisma/client/-/client-7.7.0.tgz",
@ -292,6 +347,15 @@
"zeptomatch": "2.1.0" "zeptomatch": "2.1.0"
} }
}, },
"node_modules/@prisma/driver-adapter-utils": {
"version": "7.7.0",
"resolved": "https://registry.npmmirror.com/@prisma/driver-adapter-utils/-/driver-adapter-utils-7.7.0.tgz",
"integrity": "sha512-gZXREeu6mOk7zXfGFJgh86p7Vhj0sXNKp+4Cg1tWYo7V2dfncP2qxS2BiTmbIIha8xPqItkl0WSw38RuSq1HoQ==",
"license": "Apache-2.0",
"dependencies": {
"@prisma/debug": "7.7.0"
}
},
"node_modules/@prisma/engines": { "node_modules/@prisma/engines": {
"version": "7.7.0", "version": "7.7.0",
"resolved": "https://registry.npmmirror.com/@prisma/engines/-/engines-7.7.0.tgz", "resolved": "https://registry.npmmirror.com/@prisma/engines/-/engines-7.7.0.tgz",
@ -662,6 +726,21 @@
"integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==", "integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/geojson": {
"version": "7946.0.16",
"resolved": "https://registry.npmmirror.com/@types/geojson/-/geojson-7946.0.16.tgz",
"integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==",
"license": "MIT"
},
"node_modules/@types/node": {
"version": "25.6.0",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-25.6.0.tgz",
"integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==",
"license": "MIT",
"dependencies": {
"undici-types": "~7.19.0"
}
},
"node_modules/@types/react": { "node_modules/@types/react": {
"version": "19.2.14", "version": "19.2.14",
"resolved": "https://registry.npmmirror.com/@types/react/-/react-19.2.14.tgz", "resolved": "https://registry.npmmirror.com/@types/react/-/react-19.2.14.tgz",
@ -1856,6 +1935,12 @@
"loose-envify": "cli.js" "loose-envify": "cli.js"
} }
}, },
"node_modules/lru-cache": {
"version": "10.4.3",
"resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-10.4.3.tgz",
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
"license": "ISC"
},
"node_modules/lru.min": { "node_modules/lru.min": {
"version": "1.1.4", "version": "1.1.4",
"resolved": "https://registry.npmmirror.com/lru.min/-/lru.min-1.1.4.tgz", "resolved": "https://registry.npmmirror.com/lru.min/-/lru.min-1.1.4.tgz",
@ -1871,6 +1956,22 @@
"url": "https://github.com/sponsors/wellwelwel" "url": "https://github.com/sponsors/wellwelwel"
} }
}, },
"node_modules/mariadb": {
"version": "3.5.2",
"resolved": "https://registry.npmmirror.com/mariadb/-/mariadb-3.5.2.tgz",
"integrity": "sha512-9rztrI4nouxAY/82a+RlzzZ5ie2vxu2eYclkBvTy1ATXH1B9cnvZ0O71Pzsy/mlfDb5P3HhOg0JzQKkDRhctyA==",
"license": "LGPL-2.1-or-later",
"dependencies": {
"@types/geojson": "^7946.0.16",
"@types/node": ">=18",
"denque": "^2.1.0",
"iconv-lite": "^0.7.2",
"lru-cache": "^10.4.3"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/marked": { "node_modules/marked": {
"version": "17.0.6", "version": "17.0.6",
"resolved": "https://registry.npmjs.org/marked/-/marked-17.0.6.tgz", "resolved": "https://registry.npmjs.org/marked/-/marked-17.0.6.tgz",
@ -2595,6 +2696,12 @@
"node": ">=20.18.1" "node": ">=20.18.1"
} }
}, },
"node_modules/undici-types": {
"version": "7.19.2",
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-7.19.2.tgz",
"integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==",
"license": "MIT"
},
"node_modules/use-sync-external-store": { "node_modules/use-sync-external-store": {
"version": "1.6.0", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz", "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",

View File

@ -8,8 +8,10 @@
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"dependencies": { "dependencies": {
"@prisma/adapter-mariadb": "^7.7.0",
"@prisma/client": "^7.7.0", "@prisma/client": "^7.7.0",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"mariadb": "^3.5.2",
"marked": "^17.0.6", "marked": "^17.0.6",
"next": "^14.2.3", "next": "^14.2.3",
"prisma": "^7.7.0", "prisma": "^7.7.0",

View File

@ -1,8 +1,23 @@
const axios = require('axios'); import axios from 'axios';
const cheerio = require('cheerio'); import * as cheerio from 'cheerio';
const { PrismaClient } = require('../../generated/prisma'); import { PrismaClient } from '../../generated/prisma/client.js';
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
import { createPool } from 'mariadb';
const prisma = new PrismaClient(); // 创建数据库连接池
const pool = createPool({
host: '192.168.111.111',
port: 3306,
user: 'root',
password: 'fullstack',
database: 'iboard',
connectionLimit: 5
});
// 构造 PrismaClient提供 adapter
const prisma = new PrismaClient({
adapter: new PrismaMariaDb(pool)
});
// 浙江数据开放网站URL示例实际需要根据真实网站修改 // 浙江数据开放网站URL示例实际需要根据真实网站修改
const ZHEJIANG_OPEN_DATA_URL = 'https://data.zj.gov.cn/'; const ZHEJIANG_OPEN_DATA_URL = 'https://data.zj.gov.cn/';
@ -259,6 +274,8 @@ async function scrapeSowInventory(incremental = true) {
} finally { } finally {
// 关闭Prisma连接 // 关闭Prisma连接
await prisma.$disconnect(); await prisma.$disconnect();
// 关闭数据库连接池
await pool.end();
} }
} }
@ -270,13 +287,13 @@ async function scrapeSowInventoryFull() {
} }
// 导出函数 // 导出函数
module.exports = { export {
scrapeSowInventory, scrapeSowInventory,
scrapeSowInventoryFull scrapeSowInventoryFull
}; };
// 如果直接运行此文件 // 如果直接运行此文件
if (require.main === module) { if (import.meta.url === `file://${process.argv[1]}`) {
// 默认执行增量更新 // 默认执行增量更新
// 如果需要强制全量更新,使用: scrapeSowInventoryFull() // 如果需要强制全量更新,使用: scrapeSowInventoryFull()
scrapeSowInventory().catch(error => { scrapeSowInventory().catch(error => {