diff --git a/package.json b/package.json index 2d7a0a8..f669c1c 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "cheerio": "^1.0.0-rc.3", "fs-extra": "^9.0.0", "node-readability": "^3.0.0", + "request": "^2.88.2", "think-cache": "^1.0.0", "think-cache-file": "^1.0.8", "think-logger3": "^1.0.0", diff --git a/src/config/crontab.js b/src/config/crontab.js new file mode 100644 index 0000000..eb9211e --- /dev/null +++ b/src/config/crontab.js @@ -0,0 +1,42 @@ +const request = require("request"); + +module.exports = [{ + interval: 1000 * 60 * 10, // 10分钟抓取一次 + immediate: true, + handle: async () => { + let form = { + userId: null, + lastupdataTime: new Date().getTime(), + pageNo: 1, + pageSize: 1000, + sort: "desc", + renderType: 0, + date: think.datetime(new Date(), "YYYY年MM月DD日"), + idfa: "d4995f8a0c9b2ad9182369016e376278", + os: "ios", + osv: "9.3.5" + }; + const url = "https://api.shouqu.me/api_service/api/v1/daily/dailyMark"; + request.post({ url, form }, async function (error, response, body) { + if (!error && response && response.statusCode == 200) { + let data = JSON.parse(body).data; + let list = data.list; + let dataList = []; + for (const item of list) { + dataList.push({ + id: item.articleId, + title: item.title, + url: item.url, + clickCount: item.favCount, + tagName: item.sourceName, + createdAt: think.datetime(item.updatetime > item.createtime ? item.createtime : item.updatetime), + lastClick: think.datetime(item.updatetime <= item.createtime ? item.createtime : item.updatetime), + snap: item.images_upd, + icon: item.sourceLogo + }) + } + await think.model('hot_bookmarks').addMany(dataList, { replace: true }); + } + }) + } +}] \ No newline at end of file diff --git a/update.sql b/update.sql index 90bfd1e..90be684 100644 --- a/update.sql +++ b/update.sql @@ -44,10 +44,10 @@ CHANGE COLUMN `fav_count` `clickCount` smallint(6) NULL DEFAULT 1 AFTER `url`, CHANGE COLUMN `created_by` `tagName` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `clickCount`, CHANGE COLUMN `snap_url` `snap` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `last_click`, CHANGE COLUMN `favicon_url` `icon` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `snap`, -ADD COLUMN `createAt` datetime NULL AFTER `tagName`, -ADD COLUMN `lastClick` datetime NULL AFTER `createAt`, +ADD COLUMN `createdAt` datetime NULL AFTER `tagName`, +ADD COLUMN `lastClick` datetime NULL AFTER `createdAt`, MODIFY COLUMN `id` int(11) NOT NULL AUTO_INCREMENT FIRST; -UPDATE hot_bookmarks SET createAt = FROM_UNIXTIME(created_at/1000), lastClick = FROM_UNIXTIME(last_click/1000); +UPDATE hot_bookmarks SET createdAt = FROM_UNIXTIME(created_at/1000), lastClick = FROM_UNIXTIME(last_click/1000); ALTER TABLE `hot_bookmarks` DROP COLUMN `created_at`, DROP COLUMN `last_click`;