Add App Store in-app-purchase price monitor (#581)

DO NOT MERGE before #580
This commit is contained in:
Henry Wang 2018-08-30 14:34:28 +01:00 committed by DIYgod
parent bd7fed402d
commit 9fa5242ed5
4 changed files with 538 additions and 257 deletions

File diff suppressed because it is too large Load Diff

View File

@ -160,7 +160,19 @@ Parameters
- type, App typeeither `iOS` or `mac`
- id, App Store app id, obtain from the app URL https://itunes.apple.com/cn/app/id1152443474, in this case, `id1152443474`.
- id, App Store app id, obtain from the app URL https://itunes.apple.com/us/app/id1152443474, in this case, `id1152443474`.
### 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)
Route: `/appstore/iap/:country/:id`
Parameters:
- country, App Store Country, obtain from the app URL https://itunes.apple.com/us/app/id953286746, in this case, `us`.
- id, App Store app id, obtain from the app URL https://itunes.apple.com/us/app/id953286746, in this case, `id953286746`.
## pixiv

View File

@ -434,6 +434,7 @@ router.get('/imuseum/:city/:type', require('./routes/imuseum'));
// AppStore
router.get('/appstore/update/:country/:id', require('./routes/appstore/update'));
router.get('/appstore/price/:country/:type/:id', require('./routes/appstore/price'));
router.get('/appstore/iap/:country/:id', require('./routes/appstore/in-app-purchase'));
// Hopper
router.get('/hopper/:lowestOnly/:from/:to?', require('./routes/hopper/index'));

View File

@ -0,0 +1,50 @@
const axios = require('../../utils/axios');
const url = require('url');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const country = ctx.params.country;
const id = ctx.params.id;
const link = `https://itunes.apple.com/${country}/app/${id}`;
const target = url.resolve(link, '?mt=8#see-all/in-app-purchases');
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()} is now ${$(e)
.find('h5')
.text()
.trim()}` + Date.now(),
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'}`;
ctx.state.data = {
title,
link,
item,
};
};