Last active
December 8, 2016 09:44
-
-
Save greymd/9cf3c5f69a218232ed97d1118c3a7762 to your computer and use it in GitHub Desktop.
QiitaのAdventCalendarのいいねの数をカウントするスクリプト
This file contains hidden or 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
| #!/bin/bash | |
| # Dependencies | |
| # curl, perl, paste, sort, uniq, awk | |
| curl -so- $1 | \ | |
| perl -nle 'print $_ for (m/(?<=<a href=")(http:\/\/qiita.com\/[^"]+\/items\/[^"]+)">(.*?)(?=<\/a>)/g)' | \ | |
| paste - - | sort | uniq | \ | |
| while read url title; do echo $(curl -so- $url | grep -oP '(?<=<span class="js-likecount">)\d+(?=</span>)')"\t$title\t$url" ;done | \ | |
| awk -F'\t' '{s+=$1;print $0}END{print "SUM: "s}' | |
| # Example (As of 2016/12/08) | |
| # $ advent_count.sh http://qiita.com/advent-calendar/2016/shell-script | |
| # 3 エスケープシーケンスを使ってロゴを動かす http://qiita.com/YoshihikoTakeuchi/items/c9b4fa4458bba301279c | |
| # 19 Bash $((算術式)) のすべて http://qiita.com/akinomyoga/items/2dd3f341cf15dd9c330b | |
| # 388 プログラマーの君! 騙されるな! シェルスクリプトはそう書いちゃ駄目だ!! という話 http://qiita.com/piroor/items/77233173707a0baa6360 | |
| # 9 シェルスクリプト(Bash)で作るTwitterクライアント http://qiita.com/piroor/items/a999eeef9a67283b1e56 | |
| # 7 Bashで便利なフレームワーク http://qiita.com/syui/items/b859a57ed7bbda5d74b5 | |
| # 27 シェルとファイルデスクリプタのお話 http://qiita.com/ueokande/items/c75de7c9df2bcceda7a9 | |
| # SUM: 453 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment