From ea6568c329c4779eb689386029c78718eb5bdd87 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 15:11:57 +0800 Subject: [PATCH] feat(route): add fashion network news (#7602) Co-authored-by: DIYgod --- docs/en/new-media.md | 68 ++++++++++++++++++++++++++++++ docs/new-media.md | 68 ++++++++++++++++++++++++++++++ lib/router.js | 3 ++ lib/routes/fashionnetwork/news.js | 70 +++++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 lib/routes/fashionnetwork/news.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index c6edf15c2..e16ae2b77 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -221,6 +221,74 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## Fashion Network + +### News + + + +Sectoies + +Fashion 1 + +| Ready-to-wear | Accessories | Footwear | Sports | Denim | Lingerie | Swimwear | Eyewear | Bridal wear | Textile | Miscellaneous | +| ------------- | ----------- | -------- | ------ | ----- | -------- | -------- | ------- | ----------- | ------- | ------------- | +| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 31 | + +Luxury 2 + +| Ready-to-wear | Accessories | Footwear | Watches | Jewellery | Miscellaneous | +| ------------- | ----------- | -------- | ------- | --------- | ------------- | +| 15 | 16 | 17 | 18 | 19 | 32 | + +Beauty 3 + +| Perfume | Cosmetics | Aesthetics | Wellness | Hair | Miscellaneous | +| ------- | --------- | ---------- | -------- | ---- | ------------- | +| 21 | 22 | 23 | 24 | 33 | | + +Lifestyle 4 + +| Home decor | Tableware | Hospitality | Fine foods | Tourism | Miscellaneous | +| ---------- | --------- | ----------- | ---------- | ------- | ------------- | +| 25 | 26 | 27 | 28 | 29 | 34 | + +Others 30 + +Category + +| Retail | Business | Industry | Trade shows | +| ------ | -------- | -------- | ----------- | +| 15 | 112 | 5 | 12 | + +| Innovations | Collection | Catwalks | Design | +| ----------- | ---------- | -------- | ------ | +| 113 | 114 | 60 | 70 | + +| Media | Campaigns | People | Events | Appointments | +| ----- | --------- | ------ | ------ | ------------ | +| 50 | 115 | 80 | 90 | 95 | + +Country + +| Latin America | Brazil | China | France | +| ------------- | ------ | ----- | ------ | +| pe | br | cn | fr | + +| Germany | India | Italy | Japan | +| ------- | ----- | ----- | ----- | +| de | in | it | jp | + +| Mexico | Portugal | Russia | Spain | +| ------ | -------- | ------ | ----- | +| mx | pt | ru | es | + +| Turkey | United Kingdom | USA | Worldwide | +| ------ | -------------- | --- | --------- | +| tr | uk | us | ww | + + + ## Fermilab ### News diff --git a/docs/new-media.md b/docs/new-media.md index b2e103480..0dc10836c 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -306,6 +306,74 @@ pageClass: routes +## Fashion Network + +### News + + + +Sectoies + +Fashion 1 + +| Ready-to-wear | Accessories | Footwear | Sports | Denim | Lingerie | Swimwear | Eyewear | Bridal wear | Textile | Miscellaneous | +| ------------- | ----------- | -------- | ------ | ----- | -------- | -------- | ------- | ----------- | ------- | ------------- | +| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 31 | + +Luxury 2 + +| Ready-to-wear | Accessories | Footwear | Watches | Jewellery | Miscellaneous | +| ------------- | ----------- | -------- | ------- | --------- | ------------- | +| 15 | 16 | 17 | 18 | 19 | 32 | + +Beauty 3 + +| Perfume | Cosmetics | Aesthetics | Wellness | Hair | Miscellaneous | +| ------- | --------- | ---------- | -------- | ---- | ------------- | +| 21 | 22 | 23 | 24 | 33 | | + +Lifestyle 4 + +| Home decor | Tableware | Hospitality | Fine foods | Tourism | Miscellaneous | +| ---------- | --------- | ----------- | ---------- | ------- | ------------- | +| 25 | 26 | 27 | 28 | 29 | 34 | + +Others 30 + +Category + +| Retail | Business | Industry | Trade shows | +| ------ | -------- | -------- | ----------- | +| 15 | 112 | 5 | 12 | + +| Innovations | Collection | Catwalks | Design | +| ----------- | ---------- | -------- | ------ | +| 113 | 114 | 60 | 70 | + +| Media | Campaigns | People | Events | Appointments | +| ----- | --------- | ------ | ------ | ------------ | +| 50 | 115 | 80 | 90 | 95 | + +Country + +| Latin America | Brazil | China | France | +| ------------- | ------ | ----- | ------ | +| pe | br | cn | fr | + +| Germany | India | Italy | Japan | +| ------- | ----- | ----- | ----- | +| de | in | it | jp | + +| Mexico | Portugal | Russia | Spain | +| ------ | -------- | ------ | ----- | +| mx | pt | ru | es | + +| Turkey | United Kingdom | USA | Worldwide | +| ------ | -------------- | --- | --------- | +| tr | uk | us | ww | + + + ## Focus Taiwan ### Category diff --git a/lib/router.js b/lib/router.js index 02bbb17da..125bfe61a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4220,4 +4220,7 @@ router.get('/rss3/blog', require('./routes/rss3/blog')); // 星球日报 router.get('/odaily/activity', require('./routes/odaily/activity')); +// Fashion Network +router.get('/fashionnetwork/news/:sectors?/:categories?/:language?', require('./routes/fashionnetwork/news.js')); + module.exports = router; diff --git a/lib/routes/fashionnetwork/news.js b/lib/routes/fashionnetwork/news.js new file mode 100644 index 000000000..c26bc54c9 --- /dev/null +++ b/lib/routes/fashionnetwork/news.js @@ -0,0 +1,70 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const country = ctx.params.country || 'ww'; + let sectors = ctx.params.sectors || ''; + let categories = ctx.params.categories || ''; + + sectors = sectors === 'all' ? '' : sectors; + categories = categories === 'all' ? '' : categories; + + const sectorsUrl = sectors ? 'sectors%5B%5D=' + sectors.split(',').join('§ors%5B%5D=') : ''; + const categoriesUrl = categories ? 'categs%5B%5D=' + categories.split(',').join('&categs%5B%5D=') : ''; + + const rootUrl = `https://${country}.fashionnetwork.com`; + const currentUrl = `${rootUrl}/news/s.jsonp?${sectorsUrl}&${categoriesUrl}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load( + unescape(response.data.match(/"html":"(.*)","relatedUrl"/)[1].replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1')) + .replace(/\\n/g, '') + .replace(/\\\//g, '/') + ); + + const list = $('.list-ui__title') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: item.attr('href'), + pubDate: Date.parse(item.parent().find('time').attr('datetime')), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + content('.newsTitle, .ads').remove(); + + item.description = content('div[itemprop="text"]').html(); + + return item; + }) + ) + ); + + const labels = []; + + $('.filter__label').each(function () { + labels.push($(this).text()); + }); + + ctx.state.data = { + title: `${labels.join(',') || 'All'} - FashionNetwork`, + link: `${rootUrl}/news/s?${sectorsUrl}&${categoriesUrl}`, + item: items, + }; +};