Skip to content

Commit

Permalink
feat(route): zagg new arrivals (DIYgod#12059)
Browse files Browse the repository at this point in the history
* feat(route): zagg new arrivals

* Update docs/en/shopping.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* chore: use web api instead

* chore: use query instead of params

* fix: type

* fix: link

* Update lib/v2/zagg/new-arrivals.js
---------
  • Loading branch information
EthanWng97 authored Mar 9, 2023
1 parent fe96ab5 commit bbac984
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/en/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,12 @@ Language
### PS5 stock UK

<RouteEn author="DIYgod" example="/independent/ps5-stock-uk" path="/independent/ps5-stock-uk"/>

## Zagg

### New Arrivals

<RouteEn author="NavePnow" example="/zagg/new-arrivals/brand=164&cat=3038,3041" path="/zagg/new-arrivals/:query?" :paramsDesc="['query, search page querystring']"/>

For instance, in <https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3041>, the query is `brand=164&cat=3038%2C3041`

8 changes: 8 additions & 0 deletions docs/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa

<Route author="xyqfer" example="/westore/new" path="/westore/new"/>

## Zagg

### New Arrivals

<Route author="NavePnow" example="/zagg/new-arrivals/brand=164&cat=3038,3041" path="/zagg/new-arrivals/:query?" :paramsDesc="['query,search page querystring']"/>

For instance, in <https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3041>, the query is `brand=164&cat=3038%2C3041`

## 大麦网

### 票务更新
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/zagg/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/new-arrivals/:query?': ['NavePnow'],
};
52 changes: 52 additions & 0 deletions lib/v2/zagg/new-arrivals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const cheerio = require('cheerio');
const host = 'https://www.zagg.com/en_us';
module.exports = async (ctx) => {
const query = ctx.params.query;
const params = new URLSearchParams(query);
const brands = params.get('brand');
const categories = params.get('cat');

const url = `${host}/new-arrivals`;
const response = await got({
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
method: 'post',
url,
searchParams: {
cat: categories,
brand: brands,
},
});
const products = response.data.products;

const $ = cheerio.load(products);
const list = $('.item.product.product-item')
.map(function () {
const data = {};
const details = $(this).find('.product.details-box').html();
data.link = $(this).find('.product-item-link').eq(0).attr('href');
data.title = $(this).find('.product-item-link').text();
const regex = /(https.*?)\?/;
const imgUrl = $(this).find('img').eq(0).attr('data-src').match(regex)[1];
const img = art(path.join(__dirname, 'templates/new-arrivals.art'), {
imgUrl,
});
data.description = details + img;
return data;
})
.get();
ctx.state.data = {
title: 'Zagg - New Arrivals',
link: response.url,
description: 'Zagg - New Arrivals',
item: list.map((item) => ({
title: item.title,
description: item.description,
link: item.link,
})),
};
};
16 changes: 16 additions & 0 deletions lib/v2/zagg/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
'zagg.com': {
_name: 'New Arrivals',
'.': [
{
title: 'Zagg - New Arrivals',
docs: 'https://docs.rsshub.app/shopping.html#zagg',
source: ['/en_us/new-arrivals'],
target: (_, url) => {
const queryString = url.split('?')[1];
return `/zagg/new-arrivals/${queryString}`;
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/zagg/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/new-arrivals/:query?', require('./new-arrivals'));
};
3 changes: 3 additions & 0 deletions lib/v2/zagg/templates/new-arrivals.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<img src={{imgUrl}}>
</div>

0 comments on commit bbac984

Please sign in to comment.