Skip to content

Commit

Permalink
feat(route): add Resonac (#16960)
Browse files Browse the repository at this point in the history
* Create namespace.ts

* Add files via upload

* Update dongtai.ts

* Update gonggao.ts

* Update gonggao.ts

* Update gonggao.ts

* Update dongtai.ts

* Update gonggao.ts

* Update gonggao.ts

* Update gonggao.ts

* Update gonggao.ts

* Update dongtai.ts

* Create namespace.ts

* Add files via upload

* Update articles.ts

* Update articles.ts

* Update articles.ts

* Update articles.ts

* Update articles.ts

* Update articles.ts

* Update articles.ts

* route for 日经新闻半导体,产业聚焦

* Update scienceatechnology.ts

* Update semi.ts

* Delete lib/routes/yamap directory

* Delete lib/routes/nikkei/semi.ts

* Delete lib/routes/nikkei/scienceatechnology.ts

* Update lib/routes/szftedu/dongtai.ts

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

* Update lib/routes/szftedu/namespace.ts

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

* Update lib/routes/szftedu/gonggao.ts

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

* Update gonggao.ts

* Update gonggao.ts

* Update dongtai.ts

* Update gonggao.ts

* Update gonggao.ts

* Update dongtai.ts

* Update dongtai.ts

* Update dongtai.ts

* Update gonggao.ts

* Update lib/routes/szftedu/gonggao.ts

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

* Update lib/routes/szftedu/dongtai.ts

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

* Update dongtai.ts

* Update dongtai.ts

* fix: route name

* new route: resonac products

* Update products.ts

* Update products.ts

* Update products.ts

* Update products.ts

* fix: names

* fix: remove fake pubDate

* fix: remove unecessary spaces in selectors

* fix: selectors

---------
  • Loading branch information
valuex authored Oct 4, 2024
1 parent 652f220 commit 03a00cd
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/routes/resonac/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Resonac',
url: 'www.resonac.com',
};
85 changes: 85 additions & 0 deletions lib/routes/resonac/products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
// import { parseDate } from '@/utils/parse-date';
// import timezone from '@/utils/timezone';

const baseUrl = 'https://www.resonac.com';
const host = 'https://www.resonac.com/products?intcid=glnavi_products';

export const route: Route = {
path: '/products',
categories: ['other'],
example: '/resonac/products',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: 'Products',
maintainers: ['valuex'],
handler,
description: '',
};

async function handler() {
const response = await got(host);
const pageHtml = response.data;
const $ = load(pageHtml);
const groupLists = $('div.m-panel-card-link ul li')
.toArray()
.map((el) => ({
groupName: $('a', el).text().trim(),
groupURL: baseUrl + $('a', el).attr('href'),
}));

const lists = await Promise.all(
groupLists.map((productGroup) =>
cache.tryGet(productGroup.groupURL, async () => {
const strUrl = productGroup.groupURL;
const response = await got(strUrl);
const $ = load(response.data);
const item = $('dt.m-toggle__title div span a')
.toArray()
.map((el) => ({
title: $('b', el).text().trim(),
link: baseUrl + $(el).attr('href'),
group: productGroup.groupName,
}));
return item;
})
)
);

const fullList = lists.flat(1); // flatten array
// fullList = fullList.filter((item) => item.title !== 'Empty');

const items = await Promise.all(
fullList.map((item) =>
cache.tryGet(item.link, async () => {
try {
const response = await got(item.link);
const $ = load(response.data);
const thisTitle = item.title + ' | ' + item.group;
item.title = thisTitle;
item.description = $('main div.str-section').html();
return item;
} catch (error) {
return (error as Error).message;
}
})
)
);

return {
title: 'Resonac_Products',
link: baseUrl,
description: 'Resonac_Products',
item: items,
};
}

0 comments on commit 03a00cd

Please sign in to comment.