Fix appstore/iap and examples in docs (#614)

This commit is contained in:
Henry Wang
2018-09-01 23:45:42 +08:00
committed by DIYgod
parent beaf75d4e5
commit ac0713ef67
3 changed files with 23 additions and 31 deletions
+1 -1
View File
@@ -189,7 +189,7 @@ RSSHub 同时支持 RSS 2.0、Atom 和 [JSON Feed](https://jsonfeed.org/) 输出
#### 内购价格更新(限免) <Author uid="HenryQW"/>
举例: [https://rsshub.app/appstore/iap/cn/id1152443474](https://rsshub.app/appstore/price/cn/id1152443474)
举例: [https://rsshub.app/appstore/iap/cn/id953286746](https://rsshub.app/appstore/price/cn/id953286746)
路由: `/appstore/iap/:country/:id`
+1 -1
View File
@@ -164,7 +164,7 @@ Parameters:
### App Store/Mac App Store In-App-Purchase Price Drop Alert <Author uid="HenryQW"/>
Eg: [https://rsshub.app/appstore/iap/cn/id1152443474](https://rsshub.app/appstore/price/cn/id1152443474)
Eg: [https://rsshub.app/appstore/iap/us/id953286746](https://rsshub.app/appstore/price/us/id953286746)
Route: `/appstore/iap/:country/:id`
+21 -29
View File
@@ -10,36 +10,28 @@ module.exports = async (ctx) => {
const res = await axios.get(target);
const $ = cheerio.load(res.data);
const titleTemp = $('h1')
.contents()
.first()
.text()
.trim();
const list = $('div.l-row div.we-lockup');
const item = list
.map((i, e) => ({
link,
guid: `${titleTemp} ${$(e)
.find('h3.we-lockup__title')
.text()
.trim()} ${$(e)
.find('h5')
.text()
.trim()}`,
title: `${titleTemp} ${$(e)
.find('h3.we-lockup__title')
.text()
.trim()} is now ${$(e)
.find('h5')
.text()
.trim()}`,
pubDate: new Date(Date.now()).toUTCString(),
}))
.get();
const platform = $('.we-localnav__title__product').text();
const title = `${country === 'cn' ? '内购限免提醒' : 'IAP price watcher'}: ${titleTemp} for ${platform.startsWith('App') ? 'iOS' : 'macOS'}`;
const data = JSON.parse($('#shoebox-ember-data-store')[0].firstChild.data);
const attributes = data.data.attributes;
const titleTemp = attributes.name;
const platform = attributes.kind === 'iosSoftware' ? 'iOS' : 'macOS';
let title;
let item = [];
if (attributes.hasInAppPurchases) {
title = `${country === 'cn' ? '内购限免提醒' : 'IAP price watcher'}: ${titleTemp} for ${platform}`;
const list = data.included.filter((e) => e.type === 'product/app/in-app');
item = list.map((e) => {
const title = `${e.attributes.name} is now ${e.attributes.price}`;
return {
link,
guid: title,
title,
pubDate: new Date(Date.now()).toUTCString(),
};
});
} else {
title = `${titleTemp} for ${platform} ${country === 'cn' ? ' 不包含内购项目' : 'has no IAP items'}`;
}
ctx.state.data = {
title,