From 384eb9e2c623ab3357c5e175faaafbc9b9a75613 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Thu, 12 Dec 2019 03:46:45 +0000 Subject: [PATCH] feat: add IKEA UK routes (#3578) --- docs/en/other.md | 4 +-- docs/en/shopping.md | 12 ++++++- docs/shopping.md | 10 ++++++ lib/router.js | 4 +++ lib/routes/ikea/uk/new.js | 65 +++++++++++++++++++++++++++++++++ lib/routes/ikea/uk/offer.js | 71 +++++++++++++++++++++++++++++++++++++ 6 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 lib/routes/ikea/uk/new.js create mode 100644 lib/routes/ikea/uk/offer.js diff --git a/docs/en/other.md b/docs/en/other.md index 50c9ad711..4706598d2 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -71,13 +71,13 @@ EZTV provides an official RSS feed of all torrents: https://eztv.ag/ezrss.xml ### Remote.work Job Information - + | All Jobs | Development | Design | Operation | Product | Other | Marketing | Sales | | :------: | :---------: | :----: | :-------: | :-----: | :---: | :-------: | :---: | | all | development | design | operation | product | other | marketing | sales | - + ## TransferWise diff --git a/docs/en/shopping.md b/docs/en/shopping.md index 5040c5bee..b8aaa5757 100644 --- a/docs/en/shopping.md +++ b/docs/en/shopping.md @@ -8,7 +8,17 @@ pageClass: routes ### News - + + +## IKEA + +### UK - New Product Release + + + +### UK - Offers + + ## LeBonCoin diff --git a/docs/shopping.md b/docs/shopping.md index d7ef3fb01..569dfd741 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -191,6 +191,16 @@ pageClass: routes +## 宜家 IKEA + +### 宜家 IKEA(英国)- 商品上新 + + + +### 宜家 IKEA(英国)- 促销 + + + ## 有赞 ### 商品上新 diff --git a/lib/router.js b/lib/router.js index b283a2098..fc965309f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2027,6 +2027,10 @@ router.get('/centbrowser/history', require('./routes/centbrowser/history')); // 755 router.get('/755/user/:username', require('./routes/755/user')); +// IKEA +router.get('/ikea/uk/new', require('./routes/ikea/uk/new')); +router.get('/ikea/uk/offer', require('./routes/ikea/uk/offer')); + // Mastodon router.get('/mastodon/timeline/:site/:only_media?', require('./routes/mastodon/timeline')); diff --git a/lib/routes/ikea/uk/new.js b/lib/routes/ikea/uk/new.js new file mode 100644 index 000000000..4698f5499 --- /dev/null +++ b/lib/routes/ikea/uk/new.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = 'https://www.ikea.com/gb/en/news/product-news-gallery/'; + + const response = await got.get(link); + + const $ = cheerio.load(response.data); + + const list = $('.card__link') + .get() + .map((e) => $(e).attr('href')); + const items = []; + + await Promise.all( + list.map(async (sectionUrl) => { + const response = await got.get(sectionUrl); + + const $ = cheerio.load(response.data); + + const products = $('.product-compact').get(); + + if (products.length > 0) { + for (const p of products) { + let title = + $(p) + .find('.product-compact__name') + .text() + ' '; + + title += + $(p) + .find('.product-compact__type') + .text() + .trim() + ' '; + + title += `[${$(p) + .find('.product-compact__price') + .text() + .trim()}]`; + + const link = $(p) + .find('.product-compact__spacer > a') + .attr('href'); + + items.push({ + title, + description: ` img') + .attr('src')}'>`, + link, + }); + } + } + return Promise.resolve(); + }) + ); + + ctx.state.data = { + title: 'IKEA UK - New Products', + link, + description: 'New products released by IKEA UK.', + item: items, + }; +}; diff --git a/lib/routes/ikea/uk/offer.js b/lib/routes/ikea/uk/offer.js new file mode 100644 index 000000000..414f951d5 --- /dev/null +++ b/lib/routes/ikea/uk/offer.js @@ -0,0 +1,71 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = 'https://www.ikea.com/gb/en/ikea-family/discounts/'; + + const items = []; + + const loadProductsOnPage = (data) => { + const $ = cheerio.load(data); + const products = $('.product-compact').get(); + + if (products.length > 0) { + for (const p of products) { + let title = + $(p) + .find('.product-compact__name') + .text() + ' '; + + title += + $(p) + .find('.product-compact__type') + .text() + .trim() + ' '; + + title += `[${$(p) + .find('.product-compact__comparable-price-element') + .text()} ▶️ ${$(p) + .find('.product-compact__price.product-compact__price--family') + .text()}]`; + + const link = $(p) + .find('.product-compact__spacer > a') + .attr('href'); + + items.push({ + title, + description: ` img') + .attr('src')}'>`, + link, + }); + } + } + }; + + const response = await got.get(link); + + loadProductsOnPage(response.data); + + const $ = cheerio.load(response.data); + const list = $('.text.component a') + .get() + .map((e) => $(e).attr('href')); + + if (list.length > 0) { + await Promise.all( + list.map(async (url) => { + const response = await got.get(url); + loadProductsOnPage(response.data); + }) + ); + } + + ctx.state.data = { + title: 'IKEA UK - Offers', + link, + description: 'Offers by IKEA UK.', + item: items, + }; +};