Skip to content

Commit

Permalink
✨ feat: 新增 虎扑 & 新浪网 & 新浪新闻
Browse files Browse the repository at this point in the history
- 修复历史上的今天 #63
  • Loading branch information
imsyy committed Jun 25, 2024
1 parent 6988df5 commit bf80a2e
Show file tree
Hide file tree
Showing 25 changed files with 348 additions and 36 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

> 🟢 状态正常 / 🟠 可能失效 / ❌ 无法使用 / ⚠️ 需要科学上网
<details>
<summary>查看全部接口状态</summary>

| **站点** | **类别** | **调用名称** | **状态** |
| ---------------- | ------------ | -------------- | -------- |
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
Expand All @@ -52,10 +55,13 @@
| CSDN | 排行榜 | csdn | 🟢 |
| 稀土掘金 | 热榜 | juejin | 🟢 |
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
| 新浪网 | 热榜 | sina | 🟢 |
| 新浪新闻 | 热点榜 | sina-news | 🟢 |
| 网易新闻 | 热点榜 | netease-news | 🟢 |
| 吾爱破解 | 榜单 | 52pojie ||
| 全球主机交流 | 榜单 | hostloc ||
| 虎嗅 | 24小时 | huxiu | 🟢 |
| 虎扑 | 步行街热帖 | hupu | 🟢 |
| 爱范儿 | 快讯 | ifanr | 🟢 |
| 英雄联盟 | 更新公告 | lol | 🟢 |
| 原神 | 最新消息 | genshin | 🟢 |
Expand All @@ -69,6 +75,8 @@
| 中国地震台 | 地震速报 | earthquake | 🟢 |
| 历史上的今天 | 月-日 | history | 🟢 |

</details>

## ⚙️ 使用

本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dailyhot-api",
"version": "2.0.2",
"version": "2.0.3",
"description": "An Api on Today's Hot list",
"keywords": [
"API",
Expand Down
30 changes: 30 additions & 0 deletions src/router.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,34 @@ export type RouterType = {
cover: string;
pic_share: string;
};
hupu: {
tid: number;
title: string;
replies: number;
username: string;
time: string;
url: string;
};
sina: {
base: {
base: {
uniqueId: string;
url: string;
};
};
info: {
hotValue: string;
title: string;
};
};
"sina-news": {
id: string;
title: string;
media: string;
url: string;
create_date: string;
create_time: string;
top_num: string;
time: string;
};
};
2 changes: 1 addition & 1 deletion src/routes/36kr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
name: "36kr",
title: "36氪",
type: "热榜",
parame: {
params: {
type: {
name: "热榜分类",
type: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/52pojie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
name: "52pojie",
title: "吾爱破解",
type: "榜单",
parame: {
params: {
type: {
name: "榜单分类",
type: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/acfun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
title: "AcFun",
type: "排行榜",
description: "AcFun是一家弹幕视频网站,致力于为每一个人带来欢乐。",
parame: {
params: {
type: {
name: "频道",
type: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
name: "baidu",
title: "百度",
type: "热搜榜",
parame: {
params: {
type: {
name: "热搜类别",
type: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/bilibili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
title: "哔哩哔哩",
type: "热门榜",
description: "你所热爱的,就是你的生活",
parame: {
params: {
type: {
name: "排行榜分区",
type: {
Expand Down
9 changes: 5 additions & 4 deletions src/routes/douban-movie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
};

// 数据处理
const getNumbers = (text: string | undefined) => {
if (!text) return 10000000;
const getNumbers = (text: string | undefined): number => {
if (!text) return 0;
const regex = /\d+/;
const match = text.match(regex);
if (match) {
return Number(match[0]);
} else {
return 10000000;
return 0;
}
};

Expand All @@ -44,7 +44,8 @@ const getList = async (noCache: boolean) => {
const listData = listDom.toArray().map((item) => {
const dom = $(item);
const url = dom.find("a").attr("href") || undefined;
const score = dom.find(".rating_nums").text() ?? "0.0";
const scoreDom = dom.find(".rating_nums");
const score = scoreDom.length > 0 ? scoreDom.text() : "0.0";
return {
id: getNumbers(url),
title: `【${score}${dom.find("a").attr("title")}`,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/earthquake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
name: "earthquake",
title: "中国地震台",
type: "地震速报",
parame: {
params: {
type: {
name: "速报分类",
type: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/genshin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
name: "genshin",
title: "原神",
type: "最新动态",
parame: {
params: {
type: {
name: "榜单分类",
type: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/hellogithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
title: "HelloGitHub",
type: "热门仓库",
description: "分享 GitHub 上有趣、入门级的开源项目",
parame: {
params: {
sort: {
name: "排行榜分区",
type: {
Expand Down
6 changes: 3 additions & 3 deletions src/routes/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { getCurrentDateTime } from "../utils/getTime.js";

export const handleRoute = async (c: ListContext, noCache: boolean) => {
// 获取日期
const day = c.req.query("day") || getCurrentDateTime().day;
const month = c.req.query("month") || getCurrentDateTime().month;
const day = c.req.query("day") || getCurrentDateTime(true).day;
const month = c.req.query("month") || getCurrentDateTime(true).month;
const { fromCache, data, updateTime } = await getList({ month, day }, noCache);
const routeData: RouterData = {
name: "history",
title: "历史上的今天",
type: `${month}-${day}`,
parame: {
params: {
month: "月份",
day: "日期",
},
Expand Down
2 changes: 1 addition & 1 deletion src/routes/honkai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
name: "honkai",
title: "崩坏3",
type: "最新动态",
parame: {
params: {
type: {
name: "榜单分类",
type: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/hostloc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
name: "hostloc",
title: "全球主机交流",
type: "榜单",
parame: {
params: {
type: {
name: "榜单分类",
type: {
Expand Down
51 changes: 51 additions & 0 deletions src/routes/hupu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";

export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
const routeData: RouterData = {
name: "hupu",
title: "虎扑",
type: "步行街热帖",
params: {
type: {
name: "榜单分类",
type: {
1: "主干道",
6: "恋爱区",
11: "校园区",
12: "历史区",
612: "摄影区",
},
},
},
link: "https://bbs.hupu.com/all-gambia",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};

const getList = async (options: Options, noCache: boolean) => {
const { type } = options;
const url = `https://m.hupu.com/api/v2/bbs/topicThreads?topicId=${type}&page=1`;
const result = await get({ url, noCache });
const list = result.data.data.topicThreads;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["hupu"]) => ({
id: v.tid,
title: v.title,
author: v.username,
hot: v.replies,
timestamp: null,
url: `https://bbs.hupu.com/${v.tid}.html`,
mobileUrl: v.url,
})),
};
};
Loading

0 comments on commit bf80a2e

Please sign in to comment.