本文共 2545 字,大约阅读时间需要 8 分钟。
作为一名长期运营博客园的用户,我逐渐意识到文章发表后对积分与排名的影响并不直观。博客园后台虽然提供积分与排名的查询功能,但缺乏历史数据和趋势分析,这使得我难以全面了解文章质量对排名的影响。因此,我决定开发一个工具来记录和展示积分与排名的趋势。
首先,进入博客园后台的“控件显示设置”,勾选“积分与排名”选项并保存。刷新页面后,可以在侧边栏看到当天的积分与排名。
为了自动获取当天的积分与排名,我使用curl命令下载指定页面:
curl -s 'https://www.cnblogs.com/goodcitizen/ajax/sidecolumn.aspx'
通过grep和sed命令对下载的页面内容进行解析,提取积分与排名信息,并将其存储在score.txt文件中:
curl -s 'https://www.cnblogs.com/goodcitizen/ajax/sidecolumn.aspx' | grep 'liScore' -A 6 | sed -n -e 3p -e 7p
为了自动化记录每天的积分与排名,我设置了定时任务(Windows)或crontab(Linux)来执行上述脚本。具体实现如下:
在Windows上设置定时任务,执行脚本并将结果存储在score.txt文件中。
使用crontab设置每日中午12:00执行脚本:
crontab -e0 12 * * * /home/yunhai/code/cnblogs/score.sh
使用gnuplot绘制趋势图。以下是绘图的实现步骤:
在Linux环境下安装gnuplot:
sudo yum install gnuplot
使用简单的gnuplot脚本绘制初始趋势图:
#!/usr/bin/gnuplotset terminal png size 1080,720set title "cnblogs/goodcitizen"set output "draw.png"set gridset xdata timeset timefmt "%Y-%m-%d"set format x "%m/%d"set xlabel "day(s)"set ylabel "score"plot "score.txt" using 1:2 w lp pt 5 title "score", "score.txt" using 1:3 w lp pt 5 title "rank"quit
为了更好地展示时间趋势,设置时间格式:
#!/usr/bin/gnuplotset terminal png size 1080,720set title "cnblogs/goodcitizen"set output "draw.png"set gridset xdata timeset timefmt "%Y-%m-%d"set format x "%m/%d"set xlabel "day(s)"set ylabel "score"plot "score.txt" using 1:2 w lp pt 5 title "score", "score.txt" using 1:3 w lp pt 5 title "rank"quit
以多个子图展示趋势:
#!/usr/bin/gnuplotset terminal png size 1080,720set title "cnblogs/goodcitizen"set output "goodcitizen.png"set gridset xdata timeset timefmt "%Y-%m-%d"set format x "%m/%d"set xlabel "day(s)"set ylabel "score"set size 1,1set origin 0,0set multiplotset size 0.5,0.5set origin 0,0.5ylabel "score"plot "score.txt" using 1:2 w lp pt 5 title "score"set size 0.5,0.5set origin 0.5,0.5ylabel "rank"plot "score.txt" using 1:3 w lp pt 7 title "rank"unset multiplotquit
为了更直观地展示两者关系,使用双纵轴绘制:
#!/usr/bin/gnuplotset terminal png size 1080,720set title "cnblogs/goodcitizen"set output "goodcitizen.png"set gridset xdata timeset timefmt "%Y-%m-%d"set format x "%m/%d"set xlabel "day(s)"set ylabel "score"set y2label "rank"set y2ticsset ytics nomirrorplot "score.txt" using 1:2 w lp pt 5 title "score" axis x1y1, "score.txt" using 1:3 w lp pt 7 title "rank" axis x1y1quit
通过上述工具,我能够清晰地看到博客园文章积分与排名的变化趋势。从数据中可以发现以下规律:
未来,我计划进一步优化数据分析逻辑,并探索更多的数据可视化方法,以更全面地展示博客园文章的表现。