feat: 新增 Github Trending 榜单

This commit is contained in:
imsyy 2023-12-27 10:05:15 +08:00
parent 5df634058c
commit b8c16ad88a
No known key found for this signature in database
GPG Key ID: 5D959EAB73CA095D
2 changed files with 139 additions and 131 deletions

View File

@ -38,6 +38,7 @@
| 原神 | 最新消息 | genshin | 🟢 | | 原神 | 最新消息 | genshin | 🟢 |
| 微信读书 | 飙升榜 | weread | 🟢 | | 微信读书 | 飙升榜 | weread | 🟢 |
| 快手 | 热榜 | kuaishou | 🟢 | | 快手 | 热榜 | kuaishou | 🟢 |
| Github | Trending | github | 🟢 |
| 历史上的今天 | 指定日期 | calendar | 🟢 | | 历史上的今天 | 指定日期 | calendar | 🟢 |
### 特殊接口说明 ### 特殊接口说明

View File

@ -1,3 +1,10 @@
/*
* @author: x-dr
* @date: 2023-12-25
* @customEditors: imsyy
* @lastEditTime: 2023-12-27
*/
const Router = require("koa-router"); const Router = require("koa-router");
const githubNewRouter = new Router(); const githubNewRouter = new Router();
const axios = require("axios"); const axios = require("axios");
@ -11,7 +18,6 @@ const routerInfo = {
subtitle: "trending", subtitle: "trending",
}; };
// 缓存键名 // 缓存键名
const cacheKey = "githubData"; const cacheKey = "githubData";
@ -25,8 +31,6 @@ const headers = {
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1", "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1",
}; };
// 数据处理 // 数据处理
const getData = (data) => { const getData = (data) => {
if (!data) return false; if (!data) return false;
@ -35,16 +39,25 @@ const getData = (data) => {
try { try {
$(`.Box-row`).each((i, e) => { $(`.Box-row`).each((i, e) => {
// console.log(getCheerio(e).html()); // console.log(getCheerio(e).html());
const item= cheerio.load($(e).html()) const item = cheerio.load($(e).html());
// console.log(item); // console.log(item);
const title = item("h2 a").attr('href').replace("\/","") const title = item("h2 a").attr("href").replace("/", "");
const url = `https://github.com/${title}` const url = `https://github.com/${title}`;
const excerpt = item('p').text().replace(/(^\s*)|(\s*$)/g, "") const excerpt = item("p")
const language = item('.f6 span[itemprop="programmingLanguage"]').text().replace(/(^\s*)|(\s*$)/g, "") .text()
const stars = item('.f6 a:first').text().replace(/(^\s*)|(\s*$)/g, "") .replace(/(^\s*)|(\s*$)/g, "");
const forks = item('.f6 a:eq(1)').text().replace(/(^\s*)|(\s*$)/g, "") const language = item('.f6 span[itemprop="programmingLanguage"]')
const starstoday = item('.f6 span:eq(4)').text().replace(/(^\s*)|(\s*$)/g, "") .text()
.replace(/(^\s*)|(\s*$)/g, "");
const stars = item(".f6 a:first")
.text()
.replace(/(^\s*)|(\s*$)/g, "");
const forks = item(".f6 a:eq(1)")
.text()
.replace(/(^\s*)|(\s*$)/g, "");
const starstoday = item(".f6 span:eq(4)")
.text()
.replace(/(^\s*)|(\s*$)/g, "");
dataList.push({ dataList.push({
title: title, title: title,
@ -54,7 +67,6 @@ const getData = (data) => {
stars: stars, stars: stars,
forks: forks, forks: forks,
starstoday: starstoday, starstoday: starstoday,
}); });
}); });
return dataList; return dataList;
@ -64,8 +76,6 @@ const getData = (data) => {
} }
}; };
// trending // trending
githubNewRouter.get("/github", async (ctx) => { githubNewRouter.get("/github", async (ctx) => {
console.log("获取github trending"); console.log("获取github trending");
@ -112,10 +122,7 @@ githubNewRouter.get("/github", async (ctx) => {
} }
}); });
// trending - 获取最新数据
// 豆瓣新片榜 - 获取最新数据
githubNewRouter.get("/github/new", async (ctx) => { githubNewRouter.get("/github/new", async (ctx) => {
console.log("获取github trending - 最新数据"); console.log("获取github trending - 最新数据");
try { try {