Add(route): add Mobilism

This commit is contained in:
Nite07
2022-01-27 20:31:05 +08:00
parent bdb0e125d2
commit b0be040c30
8 changed files with 204 additions and 1 deletions
+26
View File
@@ -895,3 +895,29 @@ pageClass: routes
| lingyishijain | lingyitupian | minjianqitan |
</Route>
## Mobilism
### Forums
<Route author="nitezs" example="/mobilism/forums/android/apps" path="/mobilism/forums/:category/:type" :paramsDesc="['分类', '种类']">
| 图书 | 安卓 | iPhone | iPad |
| ----- | ------- | ------ | ---- |
| books | android | iphone | ipad |
| 浪漫 | 科幻 | 经典 | 杂志 | 有声读物 | 漫画 | 应用 | 游戏 |
| ------- | ----- | -------- | --------- | ---------- | ------ | ---- | ----- |
| romance | scifi | classics | magazines | audioBooks | comics | apps | games |
</Route>
### Portal
<Route author="nitezs" example="/mobilism/portal/androidapps" path="/mobilism/portal/:type" :paramsDesc="['种类']">
| 安卓应用 | 安卓游戏 | 图书 | iPad 应用 | iPad 游戏 | iPhone 应用 | iPhone 游戏 |
| -------- | -------- | ----- | --------- | --------- | ----------- | ----------- |
| aapp | agame | ebook | ipapp | ipgame | iapp | igame |
</Route>
+12 -1
View File
@@ -36,7 +36,18 @@ pageClass: routes
### eBook Releases
<Route author="nczitzk" example="/mobilism/release" path="/mobilism/release" />
<Route author="nitezs" example="/mobilism/forums/books/romance" path="/mobilism/forums/books/:type" :paramsDesc="['种类']">
| 分类 | 分类名 |
| -------- | ---------- |
| 浪漫 | romance |
| 科幻小说 | scifi |
| 经典 | classics |
| 杂志 | magazines |
| 有声读物 | audioBooks |
| 漫画 | comics |
</Route>
## SoBooks
+61
View File
@@ -0,0 +1,61 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const utils = require('./utils');
const rootUrl = `https://forum.mobilism.org/viewforum.php?f=`;
const categeoryMap = {
books: {
romance: 1292,
scifi: 1293,
classics: 121,
magazines: 123,
audioBooks: 124,
comics: 311,
},
android: {
apps: 399,
games: 408,
},
iphone: {
apps: 316,
games: 320,
},
ipad: {
apps: 951,
games: 988,
},
};
module.exports = async (ctx) => {
const { category, type } = ctx.params;
const currentUrl = rootUrl + categeoryMap[category][type];
const response = await got.get(currentUrl, {
headers: {
cookie: await utils.login(),
},
});
const $ = cheerio.load(cheerio.load(response.data)('tbody')[1]);
const list = $('tbody > tr');
const items = list
.map((index, item) => {
item = $(item);
const title = item.find('td').first().find('a[title]').text();
const link = new URL(item.find('td').first().find('a[title]').attr('href'), 'https://forum.mobilism.org');
const date = item.find('td').first().find('small').text();
const author = item.find('td').first().find('a.username-coloured').text();
const pubDate = timezone(parseDate(date, 'DD MMM YYYY, HH:mm'), 0);
return {
title,
pubDate,
link,
author,
};
})
.get();
ctx.state.data = {
title: `Mobilism Forums ${utils.firstUpperCase(category)} ${utils.firstUpperCase(type)} Release`,
link: currentUrl,
description: `Mobilism Forums ${utils.firstUpperCase(category)} ${utils.firstUpperCase(type)} RSS`,
item: items,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/mobilism/forums/:category/:type': ['nitezs'],
'/mobilism/portal/:category/:type': ['nitezs'],
};
+50
View File
@@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const utils = require('./utils');
const get = (data) => {
const $ = cheerio.load(data);
const posts = $('div.span9 > section');
const items = posts
.map((index, item) => {
item = $(item);
return {
title: item.find('div.page-header > h3').text(),
link: new URL(item.find('div.well > a').attr('href'), 'https://forum.mobilism.org'),
author: item.find('div.well > span.muted > em > strong').text().replace('Posted by: ', ''),
description: item.find('div.well > div.postbody').text(),
pubDate: timezone(parseDate(item.find('div.well > span.muted > em').text().replace(item.find('div.well > span.muted > em > strong').text(), '').replace('at', '').replace('in', '').trim(), 'DD MMM YYYY, HH:mm'), 0),
};
})
.get();
return items;
};
module.exports = async (ctx) => {
const { type } = ctx.params;
const cookie = await utils.login();
const url = `https://forum.mobilism.org/portal.php?mode=articles&block=${type}&sk=t&sd=d&start=0`;
let items = [];
const response = await got.get(url, {
headers: {
cookie,
},
});
items = items.concat(get(response.data));
// response = await got.get(url.replace('0', '8'), {
// headers: {
// cookie,
// },
// });
// items = items.concat(get(response.data));
ctx.state.data = {
title: `Mobilism Portal ${utils.firstUpperCase(type)} Release`,
link: url,
description: `Mobilism Portal ${utils.firstUpperCase(type)} RSS`,
item: items,
};
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'mobilism.org': {
_name: 'mobilism',
'.': [
{
title: 'Forums App Release',
docs: 'https://docs.rsshub.app/bbs.html#mobilism',
source: '/',
target: '/mobilism/forum/android/apps',
},
],
},
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/forums/:category/:type', require('./forums'));
router.get('/portal/:type', require('./portal'));
};
+34
View File
@@ -0,0 +1,34 @@
const got = require('@/utils/got');
const login = async () => {
const res = await got.post('https://forum.mobilism.org/ucp.php?mode=login', {
form: {
username: 'Nite07',
password: 'hjwqgToCkGza2Y',
login: 'Login',
autologin: 'on',
sid: 'd0fc9abd2dc3148d2b8641f0bb075e64',
},
});
let cookie = '';
const cookies = res.headers['set-cookie'];
for (let i = 3; i < cookies.length; i++) {
const reg = /ppcw_29d3s(.*?);/;
const res = reg.exec(cookies[i]);
if (res) {
cookie += 'ppcw_29d3s' + res[1] + '; ';
}
}
return cookie;
};
// const login = () => {
// return 'ppcw_29d3s_sid=734f915fb8aaad5be1fd49e57886bae1; ppcw_29d3s_k=888d0e8b5da2a04f; ppcw_29d3s_u=2160336; ';
// };
const firstUpperCase = (str) => str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase());
module.exports = {
login,
firstUpperCase,
};