Skip to content

Commit

Permalink
Merge pull request #53 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Apr 3, 2024
2 parents 6e25ece + 06a995b commit 292ead0
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 53 deletions.
6 changes: 6 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ export type Config = {
ximalaya: {
token?: string;
};
xueqiu: {
cookies?: string;
};
youtube: {
key?: string;
clientId?: string;
Expand Down Expand Up @@ -619,6 +622,9 @@ const calculateValue = () => {
ximalaya: {
token: envs.XIMALAYA_TOKEN,
},
xueqiu: {
cookies: envs.XUEQIU_COOKIES,
},
youtube: {
key: envs.YOUTUBE_KEY,
clientId: envs.YOUTUBE_CLIENT_ID,
Expand Down
3 changes: 1 addition & 2 deletions lib/routes/163/dy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async function handler(ctx) {
const id = ctx.req.param('id');

const response = await got(`https://dy.163.com/v2/article/list.do?pageNo=1&wemediaId=${id}&size=10`);
const charset = response.headers['content-type'].split('=')[1];

const list = response.data.data.list.map((e) => ({
title: e.title,
Expand All @@ -40,7 +39,7 @@ async function handler(ctx) {
imgsrc: e.imgsrc,
}));

const items = await Promise.all(list.map((e) => parseDyArticle(charset, e, cache.tryGet)));
const items = await Promise.all(list.map((e) => parseDyArticle(e, cache.tryGet)));

return {
title: `网易号 - ${list[0].author}`,
Expand Down
11 changes: 3 additions & 8 deletions lib/routes/163/dy2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import iconv from 'iconv-lite';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import { parseDyArticle } from './utils';
Expand Down Expand Up @@ -31,12 +30,8 @@ async function handler(ctx) {
const id = ctx.req.param('id');
const limit = ctx.req.query('limit') ?? 30;
const url = `https://www.163.com/dy/media/${id}.html`;

const response = await got(url, { responseType: 'buffer' });

const charset = response.headers['content-type'].split('=')[1];
const data = iconv.decode(response.data, charset);
const $ = load(data);
const res = await got(url);
const $ = load(res.data);

const list = $('.tab_content ul li')
.slice(0, limit)
Expand All @@ -52,7 +47,7 @@ async function handler(ctx) {
};
});

const items = await Promise.all(list.map((item) => parseDyArticle(charset, item, cache.tryGet)));
const items = await Promise.all(list.map((item) => parseDyArticle(item, cache.tryGet)));

return {
title: `${$('head title').text()} - 网易号`,
Expand Down
6 changes: 2 additions & 4 deletions lib/routes/163/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ const __dirname = getCurrentPath(import.meta.url);

import got from '@/utils/got';
import { load } from 'cheerio';
import iconv from 'iconv-lite';
import { art } from '@/utils/render';
import * as path from 'node:path';

const parseDyArticle = (charset, item, tryGet) =>
const parseDyArticle = (item, tryGet) =>
tryGet(item.link, async () => {
const response = await got(item.link, {
responseType: 'buffer',
});

const html = iconv.decode(response.data, charset);
const $ = load(html);
const $ = load(response.data);

$('.post_main img').each((_, i) => {
if (!i.attribs.src) {
Expand Down
82 changes: 82 additions & 0 deletions lib/routes/aqicn/aqi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/:city/:pollution?',
categories: ['other'],
example: '/aqicn/beijing/pm25',
parameters: {
city: '城市拼音或地区 ID,详见[aqicn.org](http://aqicn.org/city/)',
pollution: '可选择显示更详细的空气污染成分',
},
radar: [
{
source: ['aqicn.org'],
},
],
name: '实时 AQI',
maintainers: ['ladeng07'],
handler,
url: 'aqicn.org',
descriptions: `
| 参数 | 污染成分 |
| -------- | -------- |
| pm25 | PM2.5 |
| pm10 | PM10 |
| o3 | O3 |
| no2 | NO2 |
| so2 | SO2 |
| co | CO |
举例: [https://rsshub.app/aqicn/beijing/pm25,pm10](https://rsshub.app/aqicn/beijing/pm25,pm10)
1. 显示单个污染成分,例如「pm25」, [https://rsshub.app/aqicn/beijing/pm25](https://rsshub.app/aqicn/beijing/pm25)
2. 逗号分隔显示多个污染成分,例如「pm25,pm10」,[https://rsshub.app/aqicn/beijing/pm25,pm10](https://rsshub.app/aqicn/beijing/pm25,pm10)
3. 城市子站 ID 获取方法:右键显示网页源代码,搜索 "idx" (带双冒号),后面的 ID 就是子站的 ID,如你给的链接 ID 是 4258,RSS 地址就是 [https://rsshub.app/aqicn/4258](https://rsshub.app/aqicn/4258)
`,
};

async function handler(ctx) {
const city = ctx.req.param('city');
const pollution = ctx.req.param('pollution') || [];
const pollutionType = {
so2: 'so2',
no2: 'no2',
co: 'co',
o3: 'O3',
pm25: 'PM2.5',
pm10: 'PM10',
};
const area = Number.isNaN(Number(city)) ? city : `@${city}`;

const response = await got({
method: 'get',
url: `http://aqicn.org/aqicn/json/android/${area}/json`,
});
const data = response.data;
const pollutionDetailed =
pollution.length === 0
? ''
: pollution
.split(',')
.map((item) => {
const pollutionValue = typeof data.historic[pollutionType[item]] === 'object' ? data.historic[pollutionType[item]][Object.keys(data.historic[pollutionType[item]])[0]] : data.historic[pollutionType[item]][0];
return `${pollutionType[item].toUpperCase()}:<b>${pollutionValue}</b><br>`;
})
.join('');

return {
title: `${data.namena}AQI`,
link: `https://aqicn.org/city/${data.ids.path}`,
description: `${data.namena}AQI-aqicn.org`,
item: [
{
title: `${data.namena}实时空气质量(AQI)${data.utimecn}`,
description: `${data.infocn}<br>风力:<b>${data.cwind[0]}</b>级<br>AQI:<b>${data.aqi}</b><br>${pollutionDetailed}<img src="${data.wgt}">`,
pubDate: parseDate(data.time * 1000),
guid: `${data.time}-${city}-${pollution}`,
link: `https://aqicn.org/city/${data.ids.path}`,
},
],
};
}
6 changes: 6 additions & 0 deletions lib/routes/aqicn/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '空气质量',
url: 'aqicn.org',
};
4 changes: 2 additions & 2 deletions lib/routes/baidu/tieba/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const route: Route = {
description: `| 键 | 含义 | 接受的值 | 默认值 |
| ------------ | ---------------------------------------------------------- | ------------- | ------ |
| kw | 在名为 kw 的贴吧中搜索 | 任意名称 / 无 | 无 |
| only\_thread | 只看主题帖,默认为 0 关闭 | 0/1 | 0 |
| only_thread | 只看主题帖,默认为 0 关闭 | 0/1 | 0 |
| rn | 返回条目的数量 | 1-20 | 20 |
| sm | 排序方式,0 为按时间顺序,1 为按时间倒序,2 为按相关性顺序 | 0/1/2 | 1 |
Expand All @@ -41,7 +41,7 @@ async function handler(ctx) {
const query = new URLSearchParams(ctx.req.param('routeParams'));
query.set('ie', 'utf-8');
query.set('qw', qw);
query.set('rn', query.get('rn') || 20); // Number of returned items
query.set('rn', query.get('rn') || '20'); // Number of returned items
const link = `https://tieba.baidu.com/f/search/res?${query.toString()}`;

const response = await got.get(link, {
Expand Down
31 changes: 16 additions & 15 deletions lib/routes/github/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,20 @@ async function allIssues(ctx, user, repo, limit, headers) {
};
});

const rateLimit = {
limit: Number.parseInt(response.headers['x-ratelimit-limit']),
remaining: Number.parseInt(response.headers['x-ratelimit-remaining']),
reset: parseDate(Number.parseInt(response.headers['x-ratelimit-reset']) * 1000),
resoure: response.headers['x-ratelimit-resource'],
used: Number.parseInt(response.headers['x-ratelimit-used']),
};
// response headers is broken due to #14922
// const rateLimit = {
// limit: Number.parseInt(response.headers['x-ratelimit-limit']),
// remaining: Number.parseInt(response.headers['x-ratelimit-remaining']),
// reset: parseDate(Number.parseInt(response.headers['x-ratelimit-reset']) * 1000),
// resoure: response.headers['x-ratelimit-resource'],
// used: Number.parseInt(response.headers['x-ratelimit-used']),
// };

ctx.set('json', {
title: `${user}/${repo}: Issue & Pull request comments`,
link: `${rootUrl}/${user}/${repo}`,
item: items,
rateLimit,
// rateLimit,
});

return {
Expand Down Expand Up @@ -190,13 +191,13 @@ async function singleIssue(ctx, user, repo, number, limit, headers) {
title: `${user}/${repo}: ${typeDict[type].title} #${number} - ${issue.title}`,
link: issue.html_url,
item: items,
rateLimit: {
limit: Number.parseInt(response.headers['x-ratelimit-limit']),
remaining: Number.parseInt(response.headers['x-ratelimit-remaining']),
reset: parseDate(Number.parseInt(response.headers['x-ratelimit-reset']) * 1000),
resoure: response.headers['x-ratelimit-resource'],
used: Number.parseInt(response.headers['x-ratelimit-used']),
},
// rateLimit: {
// limit: Number.parseInt(response.headers['x-ratelimit-limit']),
// remaining: Number.parseInt(response.headers['x-ratelimit-remaining']),
// reset: parseDate(Number.parseInt(response.headers['x-ratelimit-reset']) * 1000),
// resoure: response.headers['x-ratelimit-resource'],
// used: Number.parseInt(response.headers['x-ratelimit-used']),
// },
});

return {
Expand Down
15 changes: 12 additions & 3 deletions lib/routes/idaily/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import * as path from 'node:path';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

export const route: Route = {
path: ['/today/:language?', '/:language?'],
name: 'Unknown',
maintainers: [],
path: ['/:language?'],
name: '每日环球视野',
example: '/idaily',
maintainers: ['zphw', 'nczitzk'],
parameters: { language: '语言,见下表,默认为简体中文' },
radar: [
{
source: ['idai.ly/'],
},
],
handler,
description: `| 简体中文 | 繁体中文 |
| -------- | -------- |
Expand Down
51 changes: 51 additions & 0 deletions lib/routes/nymity/censorbib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { DataItem, Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
const url = 'https://censorbib.nymity.ch/';

export const route: Route = {
path: '/censorbib',
categories: ['journal'],
example: '/nymity/censorbib',
radar: [
{
source: ['censorbib.nymity.ch/'],
},
],
name: 'CensorBib Updates',
maintainers: ['xtexChooser'],
handler,
url: 'censorbib.nymity.ch/',
};

async function handler() {
const resp = await got.get(url);

const $ = load(resp.data);
const items = $('#container ul li')
.toArray()
.map((item): DataItem => {
const c = $(item);
const id = c.attr('id')!;
const title = c.find('span.paper').text().trim();
const author = c.find('span.author').text().trim();
const other = c.find('span.other').text().trim();
const download = c.find("img.icon[title='Download paper']").parent().attr('href');
const downloadBibTex = c.find("img.icon[title='Download BibTeX']").parent().attr('href');
const linkToPaper = c.find("img.icon[title='Link to paper']").parent().attr('href');
return {
title,
description: `${other}<br/><br/><a href='${download}'>Download</a><br/><a href='${downloadBibTex}'>Download BibTex</a>`,
author,
guid: id,
link: linkToPaper,
};
});

return {
title: 'CensorBib',
link: url,
description: 'CensorBib Updates',
item: items,
};
}
6 changes: 6 additions & 0 deletions lib/routes/nymity/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'nymity',
url: 'censorbib.nymity.ch',
};
6 changes: 1 addition & 5 deletions lib/routes/sehuatang/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import { CookieJar } from 'tough-cookie';
const cookieJar = new CookieJar();

const host = 'https://www.sehuatang.net/';

Expand Down Expand Up @@ -66,11 +64,10 @@ async function handler(ctx) {
const headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
Cookie: '_safe=vqd37pjm4p5uodq339yzk6b7jdt6oich',
};
await cookieJar.setCookie('_safe=vqd37pjm4p5uodq339yzk6b7jdt6oich', host);

const response = await got(link, {
cookieJar,
headers,
});
const $ = load(response.data);
Expand All @@ -93,7 +90,6 @@ async function handler(ctx) {
list.map((info) =>
cache.tryGet(info.link, async () => {
const response = await got(info.link, {
cookieJar,
headers,
});

Expand Down
Loading

0 comments on commit 292ead0

Please sign in to comment.