Skip to content

Commit

Permalink
✨ feat: 新增一些接口
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Apr 16, 2024
1 parent 067190b commit cdf2479
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 47 deletions.
93 changes: 54 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,63 @@
<div align="center">
<img alt="logo" height="120" src="./public/favicon.png" width="120"/>
<p size="20">今日热榜</p>
<h2>今日热榜</h2>
<p>一个聚合热门数据的 API 接口</p>
</div>

## 特性
## 🚩 特性

- 极快响应,便于开发
- 支持 RSS 模式和 JSON 模式
- 支持多种部署方式
- 简明的路由目录,便于新增

## 示例
## 👀 示例

> 这里是使用该 API 的示例站点
> 示例站点可能由于访问量或者长久未维护而访问异常
> 若您也使用了本 API 搭建了网站,欢迎提交您的站点链接
- [今日热榜 - https://hot.imsyy.top/](https://hot.imsyy.top/)

## 总览

> 🟢 状态正常 / 🟠 可能失效 / ❌ 无法使用
| **站点** | **类别** | **调用名称** | **状态** |
| -------------- | -------- | ------------ | -------- |
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
| AcFun | 排行榜 | acfun | 🟢 |
| 微博 | 热搜榜 | weibo | 🟢 |
| 知乎 | 热榜 | zhihu | 🟢 |
| 知乎日报 | 推荐榜 | zhihu-daily | 🟢 |
| 百度 | 热搜榜 | baidu | 🟢 |
| 抖音 | 热点榜 | douyin | 🟢 |
| 豆瓣电影 | 新片榜 | douban-movie | 🟢 |
| 豆瓣讨论小组 | 讨论精选 | douban-group | 🟢 |
| 百度贴吧 | 热议榜 | tieba | 🟢 |
| 少数派 | 热榜 | sspai | 🟢 |
| IT 之家 | 热榜 | ithome | 🟠 |
| 简书 | 热门推荐 | jianshu | 🟠 |
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
| 今日头条 | 热榜 | toutiao | 🟢 |
| 36 氪 | 热榜 | 36kr | 🟢 |
| 稀土掘金 | 热榜 | juejin | 🟢 |
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
| 网易新闻 | 热点榜 | netease-news | 🟢 |
| 英雄联盟 | 更新公告 | lol | 🟢 |
| 原神 | 最新消息 | genshin | 🟢 |
| 崩坏3 | 最新动态 | honkai | 🟢 |
| 崩坏:星穹铁道 | 最新动态 | starrail | 🟢 |
| 微信读书 | 飙升榜 | weread | 🟢 |
| NGA | 热帖 | ngabbs | 🟢 |
| HelloGitHub | Trending | hellogithub | 🟢 |

## 部署
## 🎉 总览

> 🟢 状态正常 / 🟠 可能失效 / ❌ 无法使用 / ⚠️ 需要科学上网
| **站点** | **类别** | **调用名称** | **状态** |
| ---------------- | ------------ | -------------- | -------- |
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
| AcFun | 排行榜 | acfun | 🟢 |
| 微博 | 热搜榜 | weibo | 🟢 |
| 知乎 | 热榜 | zhihu | 🟢 |
| 知乎日报 | 推荐榜 | zhihu-daily | 🟢 |
| 百度 | 热搜榜 | baidu | 🟢 |
| 抖音 | 热点榜 | douyin | 🟢 |
| 豆瓣电影 | 新片榜 | douban-movie | 🟢 |
| 豆瓣讨论小组 | 讨论精选 | douban-group | 🟢 |
| 百度贴吧 | 热议榜 | tieba | 🟢 |
| 少数派 | 热榜 | sspai | 🟢 |
| IT之家 | 热榜 | ithome | 🟠 |
| IT之家「喜加一」 | 最新动态 | ithome-xijiayi | 🟠 |
| 简书 | 热门推荐 | jianshu | 🟠 |
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
| 今日头条 | 热榜 | toutiao | 🟢 |
| 36 氪 | 热榜 | 36kr | 🟢 |
| 51CTO | 推荐榜 | 51cto | 🟢 |
| 稀土掘金 | 热榜 | juejin | 🟢 |
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
| 网易新闻 | 热点榜 | netease-news | 🟢 |
| 英雄联盟 | 更新公告 | lol | 🟢 |
| 原神 | 最新消息 | genshin | 🟢 |
| 崩坏3 | 最新动态 | honkai | 🟢 |
| 崩坏:星穹铁道 | 最新动态 | starrail | 🟢 |
| 微信读书 | 飙升榜 | weread | 🟢 |
| NGA | 热帖 | ngabbs | 🟢 |
| V2EX | 主题榜 | v2ex | ⚠️ |
| HelloGitHub | Trending | hellogithub | 🟢 |
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
| 中国地震台 | 地震速报 | earthquake | 🟢 |

## ⚙️ 部署

具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作:

Expand Down Expand Up @@ -128,14 +133,24 @@ npm run start
若您目前仅能通过 `Vercel` 进行部署,那么请暂时不要使用最新版本

## 其他
## ⚠️ 须知

- 本项目为了避免频繁请求官方数据,默认对数据做了缓存处理,默认为 `60` 分钟,如需更改,请自行修改配置
- 本项目部分接口使用了 **页面爬虫**,若违反对应页面的相关规则,请 **及时通知我去除该接口**

## 免责声明
## 📢 免责声明

- 本项目提供的 `API` 仅供开发者进行技术研究和开发测试使用。使用该 `API` 获取的信息仅供参考,不代表本项目对信息的准确性、可靠性、合法性、完整性作出任何承诺或保证。本项目不对任何因使用该 `API` 获取信息而导致的任何直接或间接损失负责。本项目保留随时更改 `API` 接口地址、接口协议、接口参数及其他相关内容的权利。本项目对使用者使用 `API` 的行为不承担任何直接或间接的法律责任
- 本项目并未与相关信息提供方建立任何关联或合作关系,获取的信息均来自公开渠道,如因使用该 `API` 获取信息而产生的任何法律责任,由使用者自行承担
- 本项目对使用 `API` 获取的信息进行了最大限度的筛选和整理,但不保证信息的准确性和完整性。使用 `API` 获取信息时,请务必自行核实信息的真实性和可靠性,谨慎处理相关事项
- 本项目保留对 `API` 的随时更改、停用、限制使用等措施的权利。任何因使用本 `API` 产生的损失,本项目不负担任何赔偿和责任

## 😘 鸣谢

特此感谢为本项目提供支持与灵感的项目

- [RSSHub](https://github.com/DIYgod/RSSHub)

## ⭐ Star History

[![Star History Chart](https://api.star-history.com/svg?repos=imsyy/DailyHotApi&type=Date)](https://star-history.com/#imsyy/DailyHotApi&Date)
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.0",
"version": "2.0.0-rc.2",
"description": "An Api on Today's Hot list",
"keywords": [
"API",
Expand Down
29 changes: 29 additions & 0 deletions src/router.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export type RouterType = {
url: string;
type: number;
};
"51cto": {
title: string;
url: string;
cover: string;
abstract: string;
source_id: number;
};
bilibili: {
bvid: string;
title: string;
Expand Down Expand Up @@ -185,4 +192,26 @@ export type RouterType = {
summary: string;
clicks_total: number;
};
v2ex: {
title: string;
url: string;
content: string;
id: number;
replies: number;
member: {
username: string;
};
};
earthquake: {
NEW_DID: string;
LOCATION_C: string;
M: string;
};
weatheralarm: {
alertid: string;
issuetime: string;
title: string;
url: string;
pic: string;
};
};
54 changes: 54 additions & 0 deletions src/routes/51cto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { getToken, sign } from "../utils/getToken/51cto.js";
import { get } from "../utils/getData.js";

export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache);
const routeData: RouterData = {
name: "51cto",
title: "51CTO",
type: "推荐榜",
link: "https://www.51cto.com/",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};

const getList = async (noCache: boolean) => {
const url = `https://api-media.51cto.com/index/index/recommend`;
const params = {
page: 1,
page_size: 50,
limit_time: 0,
name_en: "",
};
const timestamp = Date.now();
const token = (await getToken()) as string;
const result = await get({
url,
params: {
...params,
timestamp,
token,
sign: sign("index/index/recommend", params, timestamp, token),
},
noCache,
});
const list = result.data.data.data.list;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["51cto"]) => ({
id: v.source_id,
title: v.title,
cover: v.cover,
desc: v.abstract,
url: v.url,
mobileUrl: v.url,
})),
};
};
2 changes: 1 addition & 1 deletion src/routes/bilibili.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import getBiliWbi from "../utils/getBiliWbi.js";
import getBiliWbi from "../utils/getToken/bilibili.js";

export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "0";
Expand Down
76 changes: 76 additions & 0 deletions src/routes/earthquake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type { RouterData, ListContext, Options } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";

const mappings = {
O_TIME: "发震时刻(UTC+8)",
LOCATION_C: "参考位置",
M: "震级(M)",
EPI_LAT: "纬度(°)",
EPI_LON: "经度(°)",
EPI_DEPTH: "深度(千米)",
SAVE_TIME: "录入时间",
};

const typeMappings = {
1: "最近24小时地震信息",
2: "最近48小时地震信息",
3: "最近7天地震信息",
4: "最近30天地震信息",
5: "最近一年3.0级以上地震信息",
6: "最近一年地震信息",
7: "最近一年3.0级以下地震",
8: "最近一年4.0级以上地震信息",
9: "最近一年5.0级以上地震信息",
0: "最近一年6.0级以上地震信息",
};

export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "5";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
const routeData: RouterData = {
name: "earthquake",
title: "中国地震台",
type: "地震速报",
parameData: {
type: {
name: "速报分类",
type: {
...typeMappings,
},
},
},
link: "https://news.ceic.ac.cn/",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};

const getList = async (options: Options, noCache: boolean) => {
const { type } = options;
const url = `http://www.ceic.ac.cn/ajax/speedsearch?num=${type}`;
const result = await get({ url, noCache });
const data = result.data.replace(/,"page":"(.*?)","num":/, ',"num":');
const list = JSON.parse(data.substring(1, data.length - 1)).shuju;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["earthquake"]) => {
const contentBuilder = [];
const { NEW_DID, LOCATION_C, M } = v;
for (const mappingsKey in mappings) {
contentBuilder.push(`${mappings[mappingsKey]}${v[mappingsKey]}`);
}
return {
id: NEW_DID,
title: `${LOCATION_C}发生${M}级地震`,
desc: contentBuilder.join("\n"),
url: `https://news.ceic.ac.cn/${NEW_DID}.html`,
mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`,
};
}),
};
};
2 changes: 1 addition & 1 deletion src/routes/ithome-xijiayi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { get } from "../utils/getData.js";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache);
const routeData: RouterData = {
name: "ithome",
name: "ithome-xijiayi",
title: "IT之家「喜加一」",
type: "最新动态",
description: "最新最全的「喜加一」游戏动态尽在这里!",
Expand Down
48 changes: 48 additions & 0 deletions src/routes/v2ex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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") || "hot";
const { fromCache, data, updateTime } = await getList({ type }, noCache);
const routeData: RouterData = {
name: "v2ex",
title: "V2EX",
type: "主题榜",
parameData: {
type: {
name: "榜单分类",
type: {
hot: "最热主题",
latest: "最新主题",
},
},
},
link: "https://www.v2ex.com/",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};

const getList = async (options: Options, noCache: boolean) => {
const { type } = options;
const url = `https://www.v2ex.com/api/topics/${type}.json`;
const result = await get({ url, noCache });
const list = result.data.data.list;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
data: list.map((v: RouterType["v2ex"]) => ({
id: v.id,
title: v.title,
desc: v.content,
author: v.member.username,
hot: v.replies,
url: v.url,
mobileUrl: v.url,
})),
};
};
Loading

0 comments on commit cdf2479

Please sign in to comment.