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
+23 -6
View File
@@ -1,8 +1,23 @@
const axios = require('axios');
const cheerio = require('cheerio');
const { PrismaClient } = require('../../generated/prisma');
import axios from 'axios';
import * as cheerio from 'cheerio';
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(示例,实际需要根据真实网站修改)
const ZHEJIANG_OPEN_DATA_URL = 'https://data.zj.gov.cn/';
@@ -259,6 +274,8 @@ async function scrapeSowInventory(incremental = true) {
} finally {
// 关闭Prisma连接
await prisma.$disconnect();
// 关闭数据库连接池
await pool.end();
}
}
@@ -270,13 +287,13 @@ async function scrapeSowInventoryFull() {
}
// 导出函数
module.exports = {
export {
scrapeSowInventory,
scrapeSowInventoryFull
};
// 如果直接运行此文件
if (require.main === module) {
if (import.meta.url === `file://${process.argv[1]}`) {
// 默认执行增量更新
// 如果需要强制全量更新,使用: scrapeSowInventoryFull()
scrapeSowInventory().catch(error => {