Last active
May 9, 2017 05:59
-
-
Save yoshida-mediba/ed035089c42a35fa2c1c to your computer and use it in GitHub Desktop.
Talknote RSS送信スクリプト
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
#!/bin/bash | |
# | |
# send_rss_to_talknote.sh [Mail] [RSS] | |
# | |
# RSS Example: | |
# http://postd.cc/feed/ | |
# http://b.hatena.ne.jp/hotentry/it.rss | |
# | |
function getRss() { | |
rss=$(curl -sSL $1 | xmllint --format - | sed -e 's/<!\[CDATA\[//g' | sed -e 's/\]\]>//g') | |
link=($(echo "$rss" | fgrep "<link>" | awk -F"<link>|</link>" '{print $2}')) | |
title=($(echo "$rss" | fgrep -e "<title>" -e "<title type=\"html\">" | awk -F"<title>|<title type=\"html\">|</title>" '{print $2}' | tr ' ' '_')) | |
author=($(echo "$rss" | fgrep "<dc:creator>" | awk -F"<dc:creator>|</dc:creator>" '{print $2}')) | |
if [ ${#link[@]} -ne ${#title[@]} ]; then | |
link=($(echo "$rss" | fgrep "<link rel=\"alternate\"" | awk -F"<link rel=\"alternate\" type=\"text/html\" href=\"|\" />|\"/>" '{print $2}')) | |
fi | |
if [ ${#link[@]} -ne ${#title[@]} ]; then | |
link=($(echo "$rss" | fgrep "<updated>" | awk -F"<updated>|</updated>" '{print $2}')) | |
fi | |
c=0 | |
for i in ${!title[@]}; do | |
if [ $c -ge 10 ]; then | |
break | |
fi | |
if [ $i -eq 0 ]; then | |
echo "【$(echo ${title[$i]} | tr '_' ' ')】" | |
continue | |
fi | |
if fgrep "${1}|${link[$i]}" /var/tmp/sended_rss_urls >/dev/null; then | |
continue | |
else | |
echo "$(date +'%Y/%m/%d %H:%M:%S')|${1}|${link[$i]}" >> /var/tmp/sended_rss_urls | |
c=$(($c + 1)) | |
fi | |
echo | |
if [ -n "${author[$i-1]}" ]; then | |
echo $(echo ${title[$i]} | tr '_' ' ') by ${author[$i-1]} | |
else | |
echo $(echo ${title[$i]} | tr '_' ' ') | |
fi | |
echo ${link[$i]} | |
done | |
} | |
function sendMailTalknote() { | |
mime="MIME-Version: 1.0" | |
type="Content-Type: text/plain; charset=UTF-8" | |
base="Content-Transfer-Encoding: base64" | |
from="From: notifier@example.com" | |
addr="To: $1" | |
body="$2" | |
if [ $(echo -e "${body}" | wc -l) -le 2 ]; then | |
exit | |
fi | |
body=$(echo "${body}" | nkf -wMB) | |
echo -e "${mime}\n${from}\n${addr}\n${type}\n${base}\n\n${body}" | /usr/sbin/sendmail -t -i | |
} | |
function isJapanHoliday() { | |
url="https://www.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/full" | |
now=$(date +%Y%m%d) | |
if [[ -n $(curl -sS $url | fgrep "DTSTART;VALUE=DATE:$now") ]]; then | |
return 0 | |
fi | |
return 1 | |
} | |
if ! isJapanHoliday; then | |
sendMailTalknote $1 "$(getRss $2)" | |
fi |
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
0 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://b.hatena.ne.jp/hotentry/it.rss" | |
5 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://postd.cc/feed/" | |
6 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://github.com/yiisoft/yii/releases.atom" | |
7 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://github.com/php/php-src/releases.atom" | |
9 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://github.com/mysql/mysql-server/releases.atom" | |
10 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://www.ipa.go.jp/security/rss/info.rdf" | |
11 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://dev.classmethod.jp/category/cloud/feed/" | |
12 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://aws.typepad.com/aws_japan/atom.xml" | |
13 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://github.com/h2o/h2o/releases.atom" | |
14 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://news.ycombinator.com/rss?points=250" | |
15 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://www.slideshare.net/rss/user/techblogyahoo" | |
16 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://agilecatcloud.com/feed/" | |
17 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://github.com/squizlabs/PHP_CodeSniffer/releases.atom" | |
18 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://www.jpcert.or.jp/rss/jpcert.rdf" | |
19 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://l-orem.com/feed/" | |
20 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://www.debian.org/security/dsa" | |
22 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://oss.sios.com/yorozu-blog/yorozu-index/atom.xml" | |
23 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://www.publickey1.jp/atom.xml" | |
24 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://ceblog.mediba.jp/rss" | |
25 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://rhn.redhat.com/rpc/recent-errata.pxt" | |
26 10 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "https://alas.aws.amazon.com/alas.rss" | |
27 10,18 * * 1-5 /home/h-yoshida/send_rss_to_talknote.sh g-00000-00000@mail.talknote.com "http://rss.rssad.jp/rss/codezine/new/20/index.xml" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment