Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sitdownkevin/RSSHub
Browse files Browse the repository at this point in the history
  • Loading branch information
sitdownkevin committed Nov 9, 2024
2 parents 81c8086 + 8e58cea commit 6829a15
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 29 deletions.
84 changes: 84 additions & 0 deletions lib/routes/cags/edu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import ofetch from '@/utils/ofetch';
import { Route } from '@/types';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';

const host = 'https://edu.cags.ac.cn';

const titles = {
tzgg: '通知公告',
ywjx: '要闻简讯',
zs_bss: '博士生招生',
zs_sss: '硕士生招生',
zs_dxsxly: '大学生夏令营',
};

export const route: Route = {
path: '/edu/:category',
categories: ['university'],
example: '/cags/edu/tzgg',
parameters: {
category: '通知频道,可选 tzgg/ywjx/zs_bss/zs_sss/zs_dxsxly',
},
features: {
antiCrawler: false,
requireConfig: false,
requirePuppeteer: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '研究生院',
maintainers: ['Chikit-L'],
radar: [
{
source: ['edu.cags.ac.cn/'],
},
],
handler,
description: `
| 通知公告 | 要闻简讯 | 博士生招生 | 硕士生招生 | 大学生夏令营 |
| -------- | -------- | ---------- | ---------- | ------------ |
| tzgg | ywjx | zs_bss | zs_sss | zs_dxsxly |
`,
};

async function handler(ctx) {
const category = ctx.req.param('category');
const title = titles[category];

if (!title) {
throw new Error(`Invalid category: ${category}`);
}

const API_URL = `${host}/api/cms/cmsNews/pageByCmsNavBarId/${category}/1/10/0`;
const response = await ofetch(API_URL);
const data = response.data;

const items = data.map((item) => {
const id = item.id;
const title = item.title;

let pubDate = null;
if (item.publishDate) {
pubDate = parseDate(item.publishDate, 'YYYY-MM-DD');
pubDate = timezone(pubDate, 8);
}

const link = `${host}/#/dky/view/id=${id}/barId=${category}`;

return {
title,
description: item.introduction,
link,
guid: link,
pubDate,
};
});

return {
title,
link: `${host}/#/dky/list/barId=${category}/cmsNavCategory=1`,
item: items,
};
}
9 changes: 9 additions & 0 deletions lib/routes/cags/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Chinese Academy of Geological Sciences',
url: 'cags.cgs.gov.cn',
zh: {
name: '中国地质科学院',
},
};
30 changes: 17 additions & 13 deletions lib/routes/csdn/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,39 @@ export const route: Route = {
},
],
name: 'User Feed',
maintainers: [],
maintainers: ['Jkker'],
handler,
};

async function handler(ctx) {
const user = ctx.req.param('user');

const rootUrl = 'https://blog.csdn.net';
const rootUrl = 'https://rss.csdn.net';
const blogUrl = `${rootUrl}/${user}`;
const rssUrl = blogUrl + '/rss/list';
const rssUrl = blogUrl + '/rss/map';

const feed = await rssParser.parseURL(rssUrl);

const items = await Promise.all(
feed.items.map((item) =>
cache.tryGet(item.link, async () => {
const response = await got({
method: 'get',
url: item.link,
});
try {
const response = await got({
method: 'get',
url: item.link,
});

const $ = load(response.data);
const $ = load(response.data);

const description = $('#content_views').html();
const description = $('#content_views').html();

return {
...item,
description,
};
return {
...item,
description,
};
} catch {
return item;
}
})
)
);
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/telegram/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ For backward compatibility reasons, invalid \`routeParams\` will be treated as \
},
],
name: 'Channel',
maintainers: ['DIYgod', 'Rongronggg9', 'pseudoyu'],
maintainers: ['DIYgod', 'Rongronggg9', 'synchrone', 'pseudoyu'],
handler,
description: `
:::tip
Expand Down
23 changes: 15 additions & 8 deletions lib/routes/telegram/scripts/get-telegram-session.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { TelegramClient } from 'telegram';
import { StringSession } from 'telegram/sessions/index.js';
import readline from 'readline';
import debug from 'debug';

const log = debug('telegram:session');
import winston from 'winston';

function userInput(question) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
});
return new Promise((resolve) => {
rl.question(question, (answer) => {
Expand All @@ -18,6 +16,15 @@ function userInput(question) {
});
}

const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(({ level, message, timestamp }) => `${timestamp} ${level}: ${message}`)
),
transports: [new winston.transports.Console()],
});

async function getSessionString() {
const apiId = Number.parseInt(await userInput('Please enter your API ID: '));
const apiHash = await userInput('Please enter your API Hash: ');
Expand All @@ -29,16 +36,16 @@ async function getSessionString() {
phoneNumber: async () => await userInput('Please enter your phone number: '),
password: async () => await userInput('Please enter your password: '),
phoneCode: async () => await userInput('Please enter the code you received: '),
onError: (err) => log('Error:', err),
onError: (err) => logger.error(err),
});

log('You are now connected.');
logger.info('You are now connected.');
const sessionString = client.session.save();
log('Your session string is:', sessionString);
logger.info(`Your session string is: ${sessionString}`);

await client.disconnect();
return sessionString;
}

// Run the function
getSessionString().catch((error) => log('Error:', error));
getSessionString().catch((error) => logger.error(error));
1 change: 1 addition & 0 deletions lib/routes/twitter/api/web-api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const getAuth = async (retry: number) => {
const token = config.twitter.authToken[index];
const lock = await cache.get(`${lockPrefix}${token}`, false);
if (lock) {
logger.debug(`twitter debug: twitter cookie for token ${token} is locked, retry: ${retry}`);
await new Promise((resolve) => setTimeout(resolve, Math.random() * 500 + 500));
return await getAuth(retry - 1);
} else {
Expand Down
40 changes: 33 additions & 7 deletions lib/routes/xsijishe/rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ const baseUrl = 'https://xsijishe.com';

export const route: Route = {
path: '/rank/:type',
categories: ['bbs'],
categories: ['bbs', 'popular'],
example: '/xsijishe/rank/weekly',
parameters: { type: '排行榜类型: weekly | monthly' },
parameters: {
type: {
description: '排行榜类型',
options: [
{ value: 'weekly', label: '周榜' },
{ value: 'monthly', label: '月榜' },
],
},
},
features: {
requireConfig: [
{
Expand All @@ -29,35 +37,52 @@ export const route: Route = {
supportScihub: false,
},
name: '排行榜',
maintainers: ['akynazh'],
maintainers: ['akynazh', 'AiraNadih'],
handler,
};

async function handler(ctx) {
const rankType = ctx.req.param('type');
let title;
let rankId;
let index; // 用于选择第几个 li

if (rankType === 'weekly') {
title = '司机社综合周排行榜';
rankId = 'nex_recons_demens';
index = 0; // 第一个 li 是周榜
} else if (rankType === 'monthly') {
title = '司机社综合月排行榜';
rankId = 'nex_recons_demens1';
index = 1; // 第二个 li 是月榜
} else {
throw new InvalidParameterError('Invalid rank type');
}

const url = `${baseUrl}/portal.php`;
const headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
Cookie: config.xsijishe.cookie,
'User-Agent': config.xsijishe.user_agent,
};

const resp = await got(url, {
headers,
});

const redirectMatch = resp.data.match(/window\.location\.href\s*=\s*"([^"]+)"/);
if (redirectMatch) {
const redirectUrl = `${baseUrl}${redirectMatch[1]}`;
// 使用提取到的地址重新请求
const realResp = await got(redirectUrl, {
headers,
});
resp.data = realResp.data;
}

const $ = load(resp.data);
let items = $(`#${rankId} dd`)
// 根据 index 选择对应的 li,然后获取其中的 dd 元素
let items = $('.nex_recon_lists ul li')
.eq(index)
.find('.nex_recons_demens dl dd')
.toArray()
.map((item) => {
item = $(item);
Expand All @@ -68,6 +93,7 @@ async function handler(ctx) {
link: `${baseUrl}/${link}`,
};
});

items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
Expand Down

0 comments on commit 6829a15

Please sign in to comment.