diff --git a/docs/programming.md b/docs/programming.md index f7c2244b1..37b76a99d 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -152,7 +152,7 @@ GitHub 官方也提供了一些 RSS: ### 打卡 - + ## LinkedKeeper diff --git a/lib/router.js b/lib/router.js index f90f9ece5..1dff4884c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1073,7 +1073,7 @@ router.get('/hackernews/:section/:type?', require('./routes/hackernews/story')); // LeetCode router.get('/leetcode/articles', require('./routes/leetcode/articles')); -router.get('/leetcode/submission/:country/:user', require('./routes/leetcode/submission')); +router.get('/leetcode/submission/us/:user', require('./routes/leetcode/check-us')); // segmentfault router.get('/segmentfault/channel/:name', require('./routes/segmentfault/channel')); diff --git a/lib/routes/leetcode/submission.js b/lib/routes/leetcode/check-us.js similarity index 62% rename from lib/routes/leetcode/submission.js rename to lib/routes/leetcode/check-us.js index 34786a5e5..56f51b918 100644 --- a/lib/routes/leetcode/submission.js +++ b/lib/routes/leetcode/check-us.js @@ -1,16 +1,9 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const util = require('./utils'); - module.exports = async (ctx) => { - const country = ctx.params.country; const user = ctx.params.user; - let url, state, description; - if (country === 'cn') { - url = 'https://leetcode-cn.com/'; - } else { - url = 'https://leetcode.com/'; - } + const url = 'https://leetcode.com/'; const response = await got({ method: 'get', url: url + `${user}`, @@ -21,8 +14,8 @@ module.exports = async (ctx) => { const data = response.data; const $ = cheerio.load(data); const username = $('div.panel-body') - .find('h4') - .text(); + .find('p') + .text(); // 用户名 const img = $('div.panel-body') .find('img') .attr('src'); // 用户的头像 @@ -45,19 +38,13 @@ module.exports = async (ctx) => { .eq(2) .find('span') .text(); // 通过率 - if (country === 'cn') { - state = ' 的刷题动态'; - description = '解决的题目: ' + solvedQuestion + '
通过的提交: ' + acceptedSubmission + '
通过率: ' + acceptanceRate + '
' + src; - } else { - state = ' Most recent submissions'; - description = 'Solved Question: ' + solvedQuestion + '
Accepted Submission: ' + acceptedSubmission + '
Acceptance Rate: ' + acceptanceRate + '
' + src; - } - + const state = ' Most recent submissions'; + const description = 'Solved Question: ' + solvedQuestion + '
Accepted Submission: ' + acceptedSubmission + '
Acceptance Rate: ' + acceptanceRate + '
' + src; const list = $('ul.list-group') .eq(-1) .children() .get(); - const result = await util.ProcessFeed(list, country); + const result = await util.ProcessFeed(list); ctx.state.data = { title: username + state, description: description, diff --git a/lib/routes/leetcode/utils.js b/lib/routes/leetcode/utils.js index a0717946f..63b9a26fa 100644 --- a/lib/routes/leetcode/utils.js +++ b/lib/routes/leetcode/utils.js @@ -1,12 +1,7 @@ const cheerio = require('cheerio'); -const ProcessFeed = async (list, country) => { - let host; - if (country === 'us') { - host = 'https://leetcode.com'; - } else { - host = 'https://leetcode-cn.com'; - } +const ProcessFeed = async (list) => { + const host = 'https://leetcode.com'; return await Promise.all( list.map(async (item) => { const $ = cheerio.load(item); @@ -19,7 +14,6 @@ const ProcessFeed = async (list, country) => { .eq(1) .text(); // 还原相对链接为绝对链接 - const pubDate = $('span') .eq(2) .text(); @@ -27,23 +21,12 @@ const ProcessFeed = async (list, country) => { const itemUrl = host + $(bb).attr('href'); let n = 0, h = 0; - let n1, n2, n3, n4, n5, n6; - if (country === 'us') { - n1 = pubDate.search(/year/); - n2 = pubDate.search(/month/); - n3 = pubDate.search(/week/); - n4 = pubDate.search(/day/); - n5 = pubDate.search(/hour/); - n6 = pubDate.search(/minute/); - } else { - n1 = pubDate.search(/年/); - n2 = pubDate.search(/月/); - n3 = pubDate.search(/周/); - n4 = pubDate.search(/日/); - n5 = pubDate.search(/小时/); - n6 = pubDate.search(/分钟/); - } - + const n1 = pubDate.search(/year/); + const n2 = pubDate.search(/month/); + const n3 = pubDate.search(/week/); + const n4 = pubDate.search(/day/); + const n5 = pubDate.search(/hour/); + const n6 = pubDate.search(/minute/); if (n1 !== -1) { n = n + parseInt(pubDate[n1 - 2]) * 365; } @@ -76,7 +59,6 @@ const ProcessFeed = async (list, country) => { }) ); }; - module.exports = { ProcessFeed, };