feat: 添加对 【IPSW.ME】&【中国海关-拍卖、法规】& 浙江大学官网【学术、图片新闻、新闻、浙大报道等】的支持 (#3192)

This commit is contained in:
Jeason0228
2019-10-08 12:03:48 +08:00
committed by DIYgod
parent 6cfa9ae60e
commit 48c0818049
9 changed files with 343 additions and 5 deletions

View File

@@ -232,6 +232,12 @@ pageClass: routes
| 贝尔法斯特 | `/embassy/uk/belfast` |
| 曼彻斯特 | `/embassy/uk/manchester` |
## 中华人民共和国海关总署
### 拍卖信息/海关法规
<Route author="Jeason0228" example="/customs/list/paimai" path="/customs/list/:gchannel" :paramsDesc="['支持paimai,fagui等2个频道']" />
## 中华人民共和国商务部
### 政务公开

View File

@@ -86,6 +86,12 @@ pageClass: routes
<Route author="imlonghao" example="/greasyfork/zh-CN/bilibili.com" path="/greasyfork/:language/:domain?" :paramsDesc="['语言, 可在网站右上角找到, `all` 为所有语言', '按脚本生效域名过滤, 可选']"/>
## IPSW.me
### 苹果固件更新-IPSWs/OTAs 版本
<Route author="Jeason0228" example="/ipsw/index/ipsws/iPhone11,8" path="/ipsw/index/:ptype/:pname/" :paramsDesc="['填写ipsws或otas,得到不同版本的固件','产品名, `http://rsshub.app/ipsw/index/ipsws/iPod`如填写iPad则关注iPad整个系列(ptype选填为ipsws).`http://rsshub.app/ipsw/index/ipsws/iPhone11,8`如果填写具体的iPhone11,8则关注这个机型的ipsws固件信息']"/>
## Minecraft CurseForge
### Mod 更新

View File

@@ -951,6 +951,10 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
## 浙江大学
### 普通栏目 如学术/图片/新闻等
<Route author="Jeason0228" example="/zju/list/xs" path="/universities/zju/list/:type" :paramsDesc="['xs为学术,xw为新闻,5461是图片新闻,578是浙大报道,具体参数参考左侧的菜单']"/>
### 浙大研究生院
<Route author="Caicailiushui" example="/zju/grs/1" path="/universities/zju/grs/:type" :paramsDesc="['1 为 全部公告, 2 为教学管理, 3 为各类资助,4 为学科建设, 5 为海外交流']">

View File

@@ -696,6 +696,9 @@ router.get('/zaobao/znews/:type?', require('./routes/zaobao/znews'));
// Apple
router.get('/apple/exchange_repair/:country?', require('./routes/apple/exchange_repair'));
// IPSW.me
router.get('/ipsw/index/:ptype/:pname', require('./routes/ipsw/index'));
// Minecraft CurseForge
router.get('/curseforge/files/:project', require('./routes/curseforge/files'));
@@ -1026,6 +1029,9 @@ router.get('/gov/suzhou/news/:uid', require('./routes/gov/suzhou/news'));
router.get('/gov/suzhou/doc', require('./routes/gov/suzhou/doc'));
router.get('/gov/shanxi/rst/:category', require('./routes/gov/shanxi/rst'));
// 中华人民共和国-海关总署
router.get('/gov/customs/list/:gchannel', require('./routes/gov/customs/list'));
// 中华人民共和国生态环境部
router.get('/gov/mee/gs', require('./routes/gov/mee/gs'));
@@ -1229,6 +1235,7 @@ router.get('/psnine/game', require('./routes/psnine/game'));
router.get('/psnine/news', require('./routes/psnine/news'));
// 浙江大学
router.get('/zju/list/:type', require('./routes/universities/zju/list'));
router.get('/zju/physics/:type', require('./routes/universities/zju/physics'));
router.get('/zju/grs/:type', require('./routes/universities/zju/grs'));
router.get('/zju/career/:type', require('./routes/universities/zju/career'));

View File

@@ -0,0 +1,83 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://www.customs.gov.cn/';
module.exports = async (ctx) => {
const gchannel = ctx.params.gchannel;
let channelName = ``;
let link = `http://www.customs.gov.cn/customs/302249/2476857/302309/index.html`;
switch (gchannel) {
case 'paimai':
channelName = '拍卖信息';
link = `http://www.customs.gov.cn/customs/302249/2476857/302309/index.html`;
break;
case 'fagui':
channelName = '海关法规';
link = `http://www.customs.gov.cn/customs/302249/302266/08654b53-1.html`;
break;
default:
break;
}
const response = await got({
method: 'get',
url: link,
header: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const list = $('.conList_ul li')
.map(function() {
const info = {
title: $(this)
.find('a')
.text(),
link: $(this)
.find('a')
.attr('href'),
date: $(this)
.find('span')
.text(),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = url.resolve(host, info.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: itemUrl,
header: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
$('.easysite-news-operation').remove();
const description = $('.easysite-news-peruse').html();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toDateString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `中国海关-${channelName}`,
link: link,
item: out,
};
};

136
lib/routes/ipsw/index.js Normal file
View File

@@ -0,0 +1,136 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const host = 'https://ipsw.me/';
module.exports = async (ctx) => {
const pname = ctx.params.pname;
const ptype = ctx.params.ptype;
let link = `https://ipsw.me/product/` + pname;
if (pname.search(',') === -1) {
// console.log('产品线');
link = `https://ipsw.me/product/` + pname;
} else {
// console.log('具体产品');
if (ptype === 'otas') {
// console.log('otas');
link = `https://ipsw.me/` + ptype + `/` + pname;
} else if (ptype === 'ipsws') {
// console.log('ipsw');
link = `https://ipsw.me/` + pname;
}
}
// console.log(link);
const response = await got({
method: 'get',
url: link,
header: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
let list = {};
if (pname.search(',') === -1) {
list = $('.products a')
.map(function() {
const info = {
title: $(this)
.find('img')
.attr('alt'),
link: $(this).attr('href'),
};
return info;
})
.get();
} else {
list = $('.firmware')
.map(function() {
const info = {
title: $(this)
.find('td')
.eq(1)
.text(),
link: replaceurl($(this).attr('onclick')),
date: cdate(
$(this)
.find('td')
.eq(2)
.text()
.trim()
),
};
return info;
})
.get();
}
function replaceurl(e) {
e = e.replace("';", '');
e = e.replace("window.location = '/", host);
return e;
}
// 处理发布日期,以表格第一行的日期为最新的发布日期
function cdate(e) {
const removeString = e.replace('th', '');
const removend = removeString.replace('nd', '');
const replacest = removend.replace('st', '');
const rdate = replacest.replace(/ /g, ',');
// console.log(rdate);
return rdate;
}
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const itemUrl = url.resolve(host, info.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: itemUrl,
header: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const description = $('div.selector__wizard').html();
let removeString;
if (pname.search(',') === -1) {
removeString = $('tr.firmware')
.first()
.find('td')
.eq(2)
.text()
.trim();
} else {
removeString = $('div.table-responsive table tr')
.first()
.find('td')
.text()
.trim();
}
// 处理发布日期,以表格第一行的日期为最新的发布日期
removeString = removeString
.replace('th', '')
.replace('nd', '')
.replace('st', '')
.replace('rd', '');
const rdate = removeString.replace(/ /g, ',');
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(rdate).toLocaleDateString(),
guid: title,
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${pname} - ${ptype} Released`,
link: link,
description: `查看Apple-${pname}- ${ptype} 固件-是否关闭验证`,
item: out,
};
};

View File

@@ -12,6 +12,11 @@ module.exports = async (ctx) => {
});
const data = response.data;
const $ = cheerio.load(data);
// 获取版本
const version = $('small.heading-caption')
.text()
.trim();
// console.log(version);
// 判断是否已发布
const releaseString = $('.wrapper')
.first()
@@ -26,7 +31,6 @@ module.exports = async (ctx) => {
isrelease = 0;
}
// console.log(isrelease);
const list = $('.wrapper').first();
// sketch update 提供的时间 年月反了.要重新调整
const pubday = list
@@ -64,6 +68,7 @@ module.exports = async (ctx) => {
description: `${item.html()}`,
link: `https://www.sketch.com/updates/`,
pubDate: new Date(pubdateString).toLocaleDateString(),
guid: version,
};
})
.get(),
@@ -95,6 +100,7 @@ module.exports = async (ctx) => {
description: content,
link: `https://www.sketch.com/beta/`,
pubDate: new Date(pubdateString).toLocaleDateString(),
guid: version,
};
})
.get(),

View File

@@ -9,7 +9,6 @@ module.exports = async (ctx) => {
const data = response.data;
const $ = cheerio.load(data);
const list = $('div.update');
ctx.state.data = {
title: 'Sketch Release版本',
link: response.url,
@@ -35,20 +34,24 @@ module.exports = async (ctx) => {
.attr('datetime')
.substr(-4);
const pubdateString = pubmonth + `-` + pubday + `-` + pubyear;
return {
title: `${item
.find('h2.update-version-title')
.first()
.text()}`,
.text()
.trim()}`,
description: `${item.find('section.update-highlights .lead').html()}<br>
${item.find('section.update-highlights footer').html()}<br>
${item.find('aside.update-details .mask').html()}`,
link: `https://www.sketch.com/updates/${item.find('.update-version-title a').attr('href')}`,
pubDate: new Date(pubdateString).toLocaleDateString(),
guid: `${item
.find('h2.update-version-title')
.first()
.text()
.trim()}`,
};
})
.get(),
};
};

View File

@@ -0,0 +1,87 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://www.zju.edu.cn/';
module.exports = async (ctx) => {
const type = ctx.params.type || 'xs';
const link = host + type + `/list.htm`;
const response = await got({
method: 'get',
url: link,
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
function sortDate(e) {
// console.log(e);
const pubday = e.substr(-3, 2);
const pubmonth = e.substr(-6, 2);
const pubyear = e.substr(-11, 4);
const pubdateString = pubmonth + `-` + pubday + `-` + pubyear;
// console.log(pubdateString);
return pubdateString;
}
function sortUrl(e) {
let linka = host;
if (e.search('redirect') !== -1) {
linka = link;
} else {
linka = e;
}
return linka;
}
const list = $('#wp_news_w7 ul.news li')
.map(function() {
const info = {
title: $(this)
.find('a')
.text(),
link: sortUrl(
$(this)
.find('a')
.attr('href')
),
date: sortDate($(this).text()),
};
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = url.resolve(host, info.link);
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: itemUrl,
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
const description = $('.right_content').html();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toLocaleDateString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `浙江大学` + $('ul.submenu .selected').text(),
link: link,
item: out,
};
};