From b0be040c30a93c7bc27a0a385bd9490ce1715cfa Mon Sep 17 00:00:00 2001 From: Nite07 Date: Thu, 27 Jan 2022 20:31:05 +0800 Subject: [PATCH] Add(route): add Mobilism --- docs/bbs.md | 26 +++++++++++++++ docs/reading.md | 13 +++++++- lib/v2/mobilism/forums.js | 61 +++++++++++++++++++++++++++++++++++ lib/v2/mobilism/maintainer.js | 4 +++ lib/v2/mobilism/portal.js | 50 ++++++++++++++++++++++++++++ lib/v2/mobilism/radar.js | 13 ++++++++ lib/v2/mobilism/router.js | 4 +++ lib/v2/mobilism/utils.js | 34 +++++++++++++++++++ 8 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 lib/v2/mobilism/forums.js create mode 100644 lib/v2/mobilism/maintainer.js create mode 100644 lib/v2/mobilism/portal.js create mode 100644 lib/v2/mobilism/radar.js create mode 100644 lib/v2/mobilism/router.js create mode 100644 lib/v2/mobilism/utils.js diff --git a/docs/bbs.md b/docs/bbs.md index 342f9eb952..d9558893f3 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -895,3 +895,29 @@ pageClass: routes | lingyishijain | lingyitupian | minjianqitan | + +## Mobilism + +### Forums + + + +| 图书 | 安卓 | iPhone | iPad | +| ----- | ------- | ------ | ---- | +| books | android | iphone | ipad | + +| 浪漫 | 科幻 | 经典 | 杂志 | 有声读物 | 漫画 | 应用 | 游戏 | +| ------- | ----- | -------- | --------- | ---------- | ------ | ---- | ----- | +| romance | scifi | classics | magazines | audioBooks | comics | apps | games | + + + +### Portal + + + +| 安卓应用 | 安卓游戏 | 图书 | iPad 应用 | iPad 游戏 | iPhone 应用 | iPhone 游戏 | +| -------- | -------- | ----- | --------- | --------- | ----------- | ----------- | +| aapp | agame | ebook | ipapp | ipgame | iapp | igame | + + diff --git a/docs/reading.md b/docs/reading.md index 32de595741..60ac22921e 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -36,7 +36,18 @@ pageClass: routes ### eBook Releases - + + +| 分类 | 分类名 | +| -------- | ---------- | +| 浪漫 | romance | +| 科幻小说 | scifi | +| 经典 | classics | +| 杂志 | magazines | +| 有声读物 | audioBooks | +| 漫画 | comics | + + ## SoBooks diff --git a/lib/v2/mobilism/forums.js b/lib/v2/mobilism/forums.js new file mode 100644 index 0000000000..413fa923fe --- /dev/null +++ b/lib/v2/mobilism/forums.js @@ -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, + }; +}; diff --git a/lib/v2/mobilism/maintainer.js b/lib/v2/mobilism/maintainer.js new file mode 100644 index 0000000000..28dbf4aa06 --- /dev/null +++ b/lib/v2/mobilism/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/mobilism/forums/:category/:type': ['nitezs'], + '/mobilism/portal/:category/:type': ['nitezs'], +}; diff --git a/lib/v2/mobilism/portal.js b/lib/v2/mobilism/portal.js new file mode 100644 index 0000000000..1bfccf5866 --- /dev/null +++ b/lib/v2/mobilism/portal.js @@ -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, + }; +}; diff --git a/lib/v2/mobilism/radar.js b/lib/v2/mobilism/radar.js new file mode 100644 index 0000000000..436e15d944 --- /dev/null +++ b/lib/v2/mobilism/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/mobilism/router.js b/lib/v2/mobilism/router.js new file mode 100644 index 0000000000..18f3cc0402 --- /dev/null +++ b/lib/v2/mobilism/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/forums/:category/:type', require('./forums')); + router.get('/portal/:type', require('./portal')); +}; diff --git a/lib/v2/mobilism/utils.js b/lib/v2/mobilism/utils.js new file mode 100644 index 0000000000..56700c8c0b --- /dev/null +++ b/lib/v2/mobilism/utils.js @@ -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, +};