你的个人8月更文,统计一波,总点赞数,评论数,收藏数,阅读数,掘力值?

2,692 阅读5分钟

这是我参与8月更文挑战的第31天,活动详情查看:8月更文挑战

统计

日更,不再见! 统计走一遍。

需求:

  1. 过滤出参与8月更文的文章
  2. 生成markdown的列表,显示更文日期和点赞数
  3. 统计总点赞数,评论数,收藏数,阅读数
  4. 统计累计提升的掘力值

效果演示

llll.gif

我的8月更文统计结果:截止2021-08-30 23:47

---------
文章数:  30
点赞数: 5004
阅读数: 144208
收藏数: 3586
评论数: 716
---------
掘力值:5004  + 1442  =  6446

如果需要平均值,自行修改代码即可。

源代码

源码地址: 8月更文统计和汇总

怎么使用,复制到控制台,修改USER_IDMAX_COUNT执行即可,
MAX_COUNT如果你属于日更,一日一文,默认值31即可,如果一日多文,上调到一个安全数即可。

; (async function () {
    // 用户ID
    const USER_ID = "131597122679661";  
    // 需要查询的最大文章数量   
    const MAX_COUNT = 31
    
    .........其他代码
})();

思路 + 核心代码

  1. 获取文章文章列表
    文章列表不包含正文,还不能是否参与8月征文
    多次获取,直到没有文章,或者已经达到设置的获取上限
async function loopGetArticles(userId, count) {
    let results = [];
    let cursor = 0;
    let res = {
        err_no: 0,
        has_more: true,
        cursor: 0
    }
    do {
        res = await getArticles(userId, cursor);
        cursor = +res.cursor;
        results.push(...(res.data.map(art => art.article_id)));
        await delay(undefined, 16);

    } while (res.has_more && cursor < count)

    return results;
}
  1. 获取文章内容,获得文章内容,通过标题和正文双层判断是否参与8月征文

是否参与8月征文

function is8MArticle(art) {
    return art.title.endsWith("8月更文挑战") || 
    art.mark_content.slice(0, 200).indexOf("https://juejin.cn/post/6987962113788493831") >=0
}

  1. 生成markdown的列表
function generateMD(articleInfos) {
    return articleInfos.map(art => `* ${art.date} [${art.title}](https://juejin.cn/post/${art.id}) - ${art.diggCount}赞`).join('\n');
}
  1. 统计总赞数
function getTotals(articleInfos) {
    return articleInfos.reduce((total, cur) => {
        total.diggCount += cur.diggCount;
        total.viewCount += cur.viewCount;
        total.collectCount += cur.collectCount;
        total.commentCount += cur.commentCount;
        return total;
    }, {
        diggCount: 0,
        viewCount: 0,
        collectCount: 0,
        commentCount: 0
    })
}

我的8月更文列表

欢迎阅读! 欢迎关注! 欢迎一起交流!

写在最后

如果你觉得不错,你的一赞一评就是我前行的最大动力。

技术交流群请到 这里来。 或者添加我的微信 dirge-cloud,一起学习。