mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-28 03:28:35 +08:00
feat: add new route about air-level 空气质量 (#17594)
* 123 * 空气质量 * 重复代码,无用代码删除 * 格式化代码-注释重新生成 * resolve pr problem * 1. Using String() on a string is redundant. 2. example should start with / and the namespace 3.Do not start the description with line breaks. * fix: add category --------- Co-authored-by: DESKTOP-EMU7G44\randomtree <548880923@qq.com>
This commit is contained in:
co-authored by
DESKTOP-EMU7G44\randomtree
parent
e0d9b7996a
commit
100ee1f6b7
@@ -0,0 +1,49 @@
|
||||
import { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch'; // 统一使用的请求库
|
||||
import { load } from 'cheerio'; // 类似 jQuery 的 API HTML 解析器
|
||||
|
||||
export const route: Route = {
|
||||
path: '/air/:area',
|
||||
radar: [
|
||||
{
|
||||
source: ['m.air-level.com/air/:area/'],
|
||||
target: '/air/:area',
|
||||
},
|
||||
],
|
||||
parameters: {
|
||||
area: '地区',
|
||||
},
|
||||
name: '空气质量',
|
||||
maintainers: ['lifetraveler'],
|
||||
example: '/air-level/air/xian',
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const area = ctx.req.param('area');
|
||||
const currentUrl = `https://m.air-level.com/air/${area}`;
|
||||
const response = await ofetch(currentUrl);
|
||||
const $ = load(response);
|
||||
|
||||
const title = $('body > div.container > div.row.page > div:nth-child(1) > h2').text().replaceAll('[]', '');
|
||||
|
||||
const table = $('body > div.container > div.row.page > div:nth-child(1) > div:nth-child(3) > table');
|
||||
|
||||
const qt = $('body > div.container > div.row.page > div:nth-child(1) > div.aqi-dv > div > span.aqi-bg.aqi-level-2').text();
|
||||
const pubtime = $('body > div.container > div.row.page > div:nth-child(1) > div.aqi-dv > div > span.label.label-info').text();
|
||||
|
||||
const items = [
|
||||
{
|
||||
title: title + ' ' + qt + ' ' + pubtime,
|
||||
link: currentUrl,
|
||||
description: `<table border="1 solid black">${table.html()}</table>`,
|
||||
guid: pubtime,
|
||||
},
|
||||
];
|
||||
return {
|
||||
title,
|
||||
item: items,
|
||||
description: '订阅每个城市的天气质量',
|
||||
link: currentUrl,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Route } from '@/types';
|
||||
import ofetch from '@/utils/ofetch'; // 统一使用的请求库
|
||||
import { load } from 'cheerio'; // 类似 jQuery 的 API HTML 解析器
|
||||
|
||||
export const route: Route = {
|
||||
path: ['/rank/:status?'],
|
||||
radar: [
|
||||
{
|
||||
source: ['m.air-level.com/rank/:status', 'm.air-level.com/rank'],
|
||||
target: '/rank/:status',
|
||||
},
|
||||
],
|
||||
parameters: {
|
||||
status: '地区',
|
||||
},
|
||||
name: '空气质量排行',
|
||||
maintainers: ['lifetraveler'],
|
||||
example: '/air-level/rank/best,/air-level/rank',
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const status = ctx.req.param('status');
|
||||
const currentUrl = 'https://m.air-level.com/rank';
|
||||
const response = await ofetch(currentUrl);
|
||||
const $ = load(response);
|
||||
let table = '';
|
||||
let title = '';
|
||||
|
||||
const titleBest = $('body > div.container > div.row.page > div:nth-child(1) > div:nth-child(5) > h3').text().replaceAll('[]', '');
|
||||
const tableBest = $('body > div.container > div.row.page > div:nth-child(1) > div:nth-child(5) > table').html();
|
||||
const titleWorst = $('body > div.container > div.row.page > div:nth-child(1) > div:nth-child(3) > h3').text().replaceAll('[]', '');
|
||||
const tableWorst = $('body > div.container > div.row.page > div:nth-child(1) > div:nth-child(3) > table').html();
|
||||
|
||||
if (status) {
|
||||
if (status === 'best') {
|
||||
title = titleBest;
|
||||
table = `<table border="1 solid black">${tableBest}</table>`;
|
||||
}
|
||||
|
||||
if (status === 'worsest') {
|
||||
title = titleWorst;
|
||||
table = `<table border="1 solid black">${tableWorst}</table>`;
|
||||
}
|
||||
} else {
|
||||
title = $('body > div.container > div.row.page > div:nth-child(1) > h2').text().replaceAll('[]', '');
|
||||
table = `${titleBest}<br/><table border="1 solid black">${tableBest}</table><br/><table border="1 solid black">${titleWorst}<br/>${tableWorst}</table>`;
|
||||
}
|
||||
|
||||
const pubtime = $('body > div.container > div.row.page > div:nth-child(1) > h4').text();
|
||||
const items = [
|
||||
{
|
||||
title,
|
||||
link: currentUrl,
|
||||
description: table,
|
||||
guid: pubtime,
|
||||
},
|
||||
];
|
||||
return {
|
||||
title,
|
||||
item: items,
|
||||
description: '空气质量排行',
|
||||
link: currentUrl,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'Air-Level',
|
||||
url: 'air-level.com',
|
||||
description: `
|
||||
- 可以订阅每个城市的空气质量,按照拼音订阅
|
||||
- 支持订阅每天的实时排名
|
||||
`,
|
||||
categories: ['forecast'],
|
||||
lang: 'zh-CN',
|
||||
};
|
||||
Reference in New Issue
Block a user