feat: add japanpost & fix: update joinus content (#2901)

This commit is contained in:
tuzi3040
2019-08-21 23:52:36 +08:00
committed by DIYgod
parent 5199ebbee2
commit 52342a2a9f
6 changed files with 124 additions and 1 deletions

View File

@@ -664,6 +664,12 @@ Supported sub-sites
<RouteEn author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['order by type, `best` or `newest`, default to `best`']"/> <RouteEn author="HenryQW" example="/allpoetry/newest" path="/allpoetry/:order?" :paramsDesc="['order by type, `best` or `newest`, default to `best`']"/>
### Japanpost
#### Track & Trace Service
<RouteEn author="tuzi3040" example="/japanpost/EJ123456789JP" path="/japanpost/:reqCode" :paramsDesc="['Package Number']"/>
## aptonic ## aptonic
### New Dropzone Actions ### New Dropzone Actions

View File

@@ -416,7 +416,7 @@ ctx.state.data = {
### 步骤 3: 添加脚本文档 ### 步骤 3: 添加脚本文档
1. 更新 [文档 (/docs/README.md) ](https://github.com/DIYgod/RSSHub/blob/master/docs/README.md), 可以执行 `npm run docs:dev` 查看文档效果 1. 更新 [文档 (/docs/) ](https://github.com/DIYgod/RSSHub/blob/master/docs/) 目录内对应的文档, 可以执行 `npm run docs:dev` 查看文档效果
- 文档采用 vue 组件形式,格式如下: - 文档采用 vue 组件形式,格式如下:
- `author`: 路由作者,多位作者使用单个空格分隔 - `author`: 路由作者,多位作者使用单个空格分隔

View File

@@ -849,6 +849,12 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="Andiedie" example="/d2/daily" path="/d2/daily"/> <Route author="Andiedie" example="/d2/daily" path="/d2/daily"/>
## 日本郵便
### 郵便追跡サービス
<Route author="tuzi3040" example="/japanpost/EJ123456789JP" path="/japanpost/:reqCode" :paramsDesc="['运单号']"/>
## 扇贝 ## 扇贝
### 打卡 ### 打卡

View File

@@ -1581,6 +1581,9 @@ router.get('/leboncoin/ad/:query', require('./routes/leboncoin/ad.js'));
// DHL // DHL
router.get('/dhl/:id', require('./routes/dhl/shipment-tracking')); router.get('/dhl/:id', require('./routes/dhl/shipment-tracking'));
// Japanpost
router.get('/japanpost/:reqCode', require('./routes/japanpost/index'));
// 中华人民共和国商务部 // 中华人民共和国商务部
router.get('/mofcom/article/:suffix', require('./routes/mofcom/article')); router.get('/mofcom/article/:suffix', require('./routes/mofcom/article'));

View File

@@ -0,0 +1,60 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
const baseTitle = '日本郵便';
const baseUrl = 'https://trackings.post.japanpost.jp/services/srv/search/direct?locale=ja&reqCodeNo1=';
const util = new utils();
util.expandEven();
util.expandReverse();
module.exports = async (ctx) => {
const reqCode = ctx.params.reqCode;
const link = baseUrl + reqCode;
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
const list = $('.tableType01')
.eq(1)
.find('tr')
.slice(2);
const listEven = list.even();
const packageType = $('.tableType01')
.eq(0)
.find('tr')
.eq(1)
.find('td')
.eq(1)
.text();
ctx.state.data = {
title: `${baseTitle} ${packageType} ${reqCode}`,
link: link,
description: 'Reserved for further development.',
item: listEven
.reverse()
.map((index, item) => {
item = $(item);
const itemTd = item.find('td');
const itemTitle = itemTd.eq(1).text() + ' ' + itemTd.eq(4).text() + ' ' + itemTd.eq(3).text();
const itemDescription = itemTd.eq(2).text();
const itemPubDateText = itemTd.eq(0).text();
const itemGuid = util.generateGuid(itemDescription + itemPubDateText);
return {
title: itemTitle,
description: itemDescription,
pubDate: new Date(itemPubDateText),
link: link,
guid: itemGuid.slice(0, 32),
};
})
.get(),
};
};

View File

@@ -0,0 +1,48 @@
const cheerio = require('cheerio');
const crypto = require('crypto');
function utils() {
this.expandOdd = function() {
cheerio.prototype.odd = function() {
const odds = [];
this.each(function(index, item) {
if (index % 2 === 1) {
odds.push(item);
}
});
return cheerio(odds);
};
};
this.expandEven = function() {
cheerio.prototype.even = function() {
const evens = [];
this.each(function(index, item) {
if (index % 2 === 0) {
evens.push(item);
}
});
return cheerio(evens);
};
};
this.expandReverse = function() {
cheerio.prototype.reverse = function() {
const reverses = [];
this.each(function(index, item) {
reverses.push(item);
});
reverses.reverse();
return cheerio(reverses);
};
};
this.generateGuid = function(t) {
const hash = crypto.createHash('sha512');
hash.update(t);
const r = hash.digest('hex').toUpperCase();
return r;
};
}
module.exports = utils;