Skip to content

Commit

Permalink
Merge pull request #118 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 Dec 30, 2023
2 parents 0d02237 + 6e244aa commit ae01f29
Show file tree
Hide file tree
Showing 21 changed files with 296 additions and 57 deletions.
25 changes: 25 additions & 0 deletions lib/v2/lifeweek/channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const got = require('@/utils/got');
const getRssItem = require('./utils');

const rootApiUrl = 'https://www.lifeweek.com.cn/api/userWebFollow/getFollowTagContentList?type=3&sort=2&tagId';
const rootUrl = 'https://www.lifeweek.com.cn/column';
const articleRootUrl = 'https://www.lifeweek.com.cn/article';

module.exports = async (ctx) => {
const channel = ctx.params.id;
const url = `${rootApiUrl}=${channel}`;
const { data } = await got(url);
const result = data.model.articleResponseList;
const items = await Promise.all(
result.map((item) => {
const articleLink = `${articleRootUrl}/${item.id}`;
return ctx.cache.tryGet(articleLink, () => getRssItem(item, articleLink));
})
);

ctx.state.data = {
title: data.model.tagName,
link: `${rootUrl}/${channel}`,
item: items,
};
};
4 changes: 4 additions & 0 deletions lib/v2/lifeweek/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/channel/:channel': ['changren-wcr'],
'/tag/:tag': ['changren-wcr'],
};
19 changes: 19 additions & 0 deletions lib/v2/lifeweek/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'lifeweek.com.cn': {
_name: '三联生活周刊',
'.': [
{
title: '栏目',
docs: 'https://docs.rsshub.app/routes/traditional-media#san-lian-sheng-huo-zhou-kan',
source: ['/column/:channel'],
target: '/lifeweek/channel/:channel',
},
{
title: '标签',
docs: 'https://docs.rsshub.app/routes/traditional-media#san-lian-sheng-huo-zhou-kan',
source: ['/articleList/:tag'],
target: '/lifeweek/tag/:tag',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/lifeweek/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/channel/:id', require('./channel'));
router.get('/tag/:id', require('./tag'));
};
24 changes: 24 additions & 0 deletions lib/v2/lifeweek/tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const got = require('@/utils/got');
const getRssItem = require('./utils');
const rootApiUrl = 'https://www.lifeweek.com.cn/api/userWebFollow/getFollowTagContentList?type=4&sort=2&tagId';
const rootUrl = 'https://www.lifeweek.com.cn/articleList';
const articleRootUrl = 'https://www.lifeweek.com.cn/article';

module.exports = async (ctx) => {
const tag = ctx.params.id;
const url = `${rootApiUrl}=${tag}`;
const { data } = await got(url);
const result = data.model.articleResponseList;
const items = await Promise.all(
result.map((item) => {
const articleLink = `${articleRootUrl}/${item.id}`;
return ctx.cache.tryGet(articleLink, () => getRssItem(item, articleLink));
})
);

ctx.state.data = {
title: data.model.tagName,
link: `${rootUrl}/${tag}`,
item: items,
};
};
18 changes: 18 additions & 0 deletions lib/v2/lifeweek/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const articleApiRootUrl = 'https://www.lifeweek.com.cn/api/article';

async function getRssItem(item, articleLink) {
const articleApiLink = `${articleApiRootUrl}/${item.id}`;
const { data } = await got(articleApiLink);
const time = timezone(parseDate(item.pubTime), +8);
return {
title: item.title,
description: data.model.content,
link: articleLink,
pubDate: time,
};
}

module.exports = getRssItem;
3 changes: 3 additions & 0 deletions lib/v2/medieval-china/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/': ['artefaritaKuniklo'],
};
44 changes: 44 additions & 0 deletions lib/v2/medieval-china/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const baseUrl = 'https://medieval-china.club';
const { data: response } = await got(baseUrl);
const $ = cheerio.load(response);
const posts = JSON.parse(
$('script:contains("window.localPosts")')
.text()
.match(/window\.localPosts = JSON\.parse\('(.*)'\);/)[1]
)
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
.map((item) => ({
title: item.title,
link: `${baseUrl}${item.path}`,
pubDate: timezone(parseDate(item.date), +8),
}));
const items = await Promise.all(
posts.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
const imgSrc = $('img').attr('data-original');
$('img').attr('src', `${baseUrl}${imgSrc}`);
$('.head-mask').remove();
$('div.lover-box').remove();
item.description = $('article').first().html();
return item;
})
)
);

ctx.state.data = {
title: '中国的中古',
link: baseUrl,
item: items,
image: 'https://medieval-china.club/images/icons/favicon-144x144.png',
description:
'世界那么大,你无法去到每一个地方,感受每一处风景;时间那么长,那些逝去的人你也终将无法与之谋面。而通过古人之文字,今人之分享,你可以领略以前风光之奇绝瑰玮,感受逝人之人情冷暖。中古就是这么一个地方,大家来自全球各地,不同时区,不同性别,不同身份,不同职业,但是大家都被中古的绚烂华章聚集在一起,哀其所哀,乐其所乐。这是一个虚拟的世界,但是我们仿佛跨越千里而来,谈一场绝世爱恋,今夕何夕!仅以此网站献给中古club的每一位成员,契阔谈宴,西园不芜!',
};
};
13 changes: 13 additions & 0 deletions lib/v2/medieval-china/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'medieval-china.club': {
_name: '中国的中古',
'.': [
{
title: '首页',
docs: 'https://docs.rsshub.app/routes/reading#zhong-guo-de-zhong-shou-ye',
source: '/',
target: '/medieval-china',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/medieval-china/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/', require('./post'));
};
67 changes: 47 additions & 20 deletions lib/v2/qweather/3days.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,72 @@ const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const config = require('@/config').value;
const rootUrl = 'https://devapi.qweather.com/v7/weather/3d?';

const WEATHER_API = 'https://devapi.qweather.com/v7/weather/3d';
const AIR_QUALITY_API = 'https://devapi.qweather.com/v7/air/5d';
const CIRY_LOOKUP_API = 'https://geoapi.qweather.com/v2/city/lookup';
const author = 'QWeather';

module.exports = async (ctx) => {
if (!config.hefeng.key) {
throw Error('QWeather RSS is disabled due to the lack of <a href="https://docs.rsshub.app/zh/install/config#%E5%92%8C%E9%A3%8E%E5%A4%A9%E6%B0%94">relevant config</a>');
}
const id = await ctx.cache.tryGet(ctx.params.location + '_id', async () => {
const response = await got(`https://geoapi.qweather.com/v2/city/lookup?location=${ctx.params.location}&key=${config.hefeng.key}`);
const data = [];
for (const i in response.data.location) {
data.push(response.data.location[i]);
}
return data[0].id;
const response = await got(`${CIRY_LOOKUP_API}?location=${ctx.params.location}&key=${config.hefeng.key}`);
return response.data.location[0].id;
});
const requestUrl = rootUrl + 'key=' + config.hefeng.key + '&location=' + id;
const responseData = await ctx.cache.tryGet(
const weatherData = await ctx.cache.tryGet(
ctx.params.location,
async () => {
const response = await got(requestUrl);
const response = await got(`${WEATHER_API}?key=${config.hefeng.key}&location=${id}`);
return response.data;
},
config.cache.contentExpire,
false
);
const data = [];
for (const i in responseData.daily) {
data.push(responseData.daily[i]);
}
const items = data.map((item) => ({
title: `${item.fxDate}: ${item.textDay === item.textNight ? item.textDay : item.textDay + '转' + item.textNight}`,
const airQualityData = await ctx.cache.tryGet(
`qweather:air:${ctx.params.location}`,
async () => {
const airQualityResponse = await got(`${AIR_QUALITY_API}?location=${id}&key=${config.hefeng.key}`);
return airQualityResponse.data;
},
config.cache.contentExpire,
false
);
// merge weather data with air quality data
const combined = {
updateTime: weatherData.updateTime,
fxLink: weatherData.fxLink,
daily: weatherData.daily.map((weatherItem) => {
const dailyAirQuality = airQualityData.daily.find((airQualityItem) => airQualityItem.fxDate === weatherItem.fxDate);
if (dailyAirQuality) {
return {
...weatherItem,
aqi: dailyAirQuality.aqi,
aqiLevel: dailyAirQuality.level,
aqiCategory: dailyAirQuality.category,
aqiPrimary: dailyAirQuality.primary,
};
}
return weatherItem;
}),
};
const items = combined.daily.map((item) => ({
title: `${item.fxDate}: ${item.textDay === item.textNight ? item.textDay : item.textDay + '转' + item.textNight} ${item.tempMin}~${item.tempMax}℃`,
description: art(path.join(__dirname, 'templates/3days.art'), {
item,
}),
pubDate: responseData.updateTime,
pubDate: combined.updateTime,
guid: '位置:' + ctx.params.location + '--日期:' + item.fxDate,
link: responseData.fxLink,
link: combined.fxLink,
author,
}));

ctx.state.data = {
title: ctx.params.location + '未来三天天气',
description: ctx.params.location + '未来三天天气情况,使用和风彩云api',
description: ctx.params.location + '未来三天天气情况,使用和风彩云 API (包括空气质量)',
item: items,
link: responseData.fxLink,
link: combined.fxLink,
author,
};
};
2 changes: 1 addition & 1 deletion lib/v2/qweather/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
'/3days/:location': ['Rein-Ou'],
'/3days/:location': ['Rein-Ou', 'la3rence'],
'/now/:location': ['Rein-Ou'],
};
2 changes: 2 additions & 0 deletions lib/v2/qweather/templates/3days.art
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<br>
<text>相对湿度:{{item.humidity}}%</text>
<br>
<text>空气质量指数:{{item.aqi}} ({{item.aqiCategory}})</text>
<br>
<text>大气压强:{{item.pressure}}百帕</text>
<br>
<text>紫外线强度:{{item.uvIndex}}</text>
Expand Down
61 changes: 35 additions & 26 deletions lib/v2/shmeea/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const baseURL = 'http://www.shmeea.edu.cn';
const rootUrl = baseURL + '/page/08000/index.html';
const response = await got({
method: 'get',
url: rootUrl,
});
const id = ctx.params.id ?? '08000';
const baseURL = 'https://www.shmeea.edu.cn';
const link = `${baseURL}/page/${id}/index.html`;

const data = response.data;
const response = await got(link);
const $ = cheerio.load(response.data);

const $ = cheerio.load(data);
const title = `上海市教育考试院-${$('#main .pageh4-tit').text().trim()}`;

const list = $('#main .pageList li');
const list = $('#main .pageList li')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('a').attr('title') || item.find('a').text(),
link: new URL(item.find('a').attr('href'), baseURL).href,
pubDate: parseDate(item.find('.listTime').text().trim(), 'YYYY-MM-DD'),
};
});

const items = await Promise.all(
list.map(async (i, item) => {
item = $(item);
const link = baseURL + item.find('a').attr('href');
const description = await ctx.cache.tryGet(link, async () => {
const result = await got.get(link);
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (!item.link.endsWith('.html') || new URL(item.link).hostname !== new URL(baseURL).hostname) {
return item;
}

const result = await got(item.link);
const $ = cheerio.load(result.data);

return $('#ivs_content').html();
});
return {
title: item.find('a').text(),
pubDate: new Date(item.find('.listTime').text()),
link,
description,
};
})
const description = $('#ivs_content').html();
const pbTimeText = $('#ivs_title .PBtime').text().trim();

item.description = description;
item.pubDate = pbTimeText ? timezone(parseDate(pbTimeText, 'YYYY-MM-DD HH:mm:ss'), +8) : item.pubDate;

return item;
})
)
);

ctx.state.data = {
title: '上海市教育考试院',
description: '消息速递',
link: baseURL,
title,
link,
item: items,
};
};
2 changes: 1 addition & 1 deletion lib/v2/shmeea/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
'/': ['jialinghui'],
'/:id?': ['jialinghui', 'Misaka13514'],
'/self-study': ['h2ws'],
};
13 changes: 8 additions & 5 deletions lib/v2/shmeea/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ module.exports = {
_name: '上海市教育考试院',
www: [
{
title: '消息速递',
docs: 'https://docs.rsshub.app/routes/other#shang-hai-shi-jiao-yu-kao-shi-yuan',
source: ['/'],
target: '/shmeea',
title: '消息',
docs: 'https://docs.rsshub.app/routes/study#shang-hai-shi-jiao-yu-kao-shi-yuan',
source: ['/page/:id?/index.html'],
target: (params, url, document) => {
const li = document.querySelector('#main .pageList li');
return li ? '/shmeea/:id?' : '';
},
},
{
title: '自学考试通知公告',
docs: 'https://docs.rsshub.app/routes/other#shang-hai-shi-jiao-yu-kao-shi-yuan',
docs: 'https://docs.rsshub.app/routes/study#shang-hai-shi-jiao-yu-kao-shi-yuan',
source: ['/page/04000/index.html', '/'],
target: '/shmeea/self-study',
},
Expand Down
2 changes: 1 addition & 1 deletion lib/v2/shmeea/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (router) {
router.get('/', require('./index'));
router.get('/self-study', require('./self-study'));
router.get('/:id?', require('./index'));
};
Loading

0 comments on commit ae01f29

Please sign in to comment.