-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add route of Yamap (#16902)
* 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/nikkei/semi.ts * Delete lib/routes/nikkei/scienceatechnology.ts * Update articles.ts * Update namespace.ts * Update articles.ts * Update articles.ts * Delete lib/routes/szftedu directory * fix: category * fix: typo ---------
- Loading branch information
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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://yamap.com/activities/'; | ||
const host = 'https://api.yamap.com/v3/activities?page=1&per=24'; | ||
|
||
export const route: Route = { | ||
path: '/', | ||
categories: ['travel'], | ||
example: '/yamap', | ||
parameters: {}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
name: '文章', | ||
maintainers: ['valuex'], | ||
handler, | ||
description: '', | ||
}; | ||
|
||
async function handler() { | ||
const link = host; | ||
const response = await got(link); | ||
const metadata = response.data; | ||
// const recordNum = metadata.activities.length - 1 ; | ||
|
||
const lists = metadata.activities.map((item) => ({ | ||
title: item.title, | ||
link: baseUrl + item.id.toString(), | ||
pubDate: parseDate(item.created_at), | ||
location: item.map.name || 'Japan', | ||
})); | ||
|
||
const items = await Promise.all( | ||
lists.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const response = await got(item.link); | ||
const $ = load(response.data); | ||
item.title = item.title + '-' + item.location; | ||
item.description = $('div.ActivitiesId__Body main').html(); | ||
item.pubDate = timezone(parseDate($('span[class=ActivityDetailTabLayout__Middle__Date]').text()), 8); | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: 'Yamap', | ||
link: baseUrl, | ||
description: 'Yamap', | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'YAMAP', | ||
url: 'yamap.com', | ||
}; |