More Related Content
More from Yoshitake Takata (20)
広島IT勉強会カレンダー(仮)と自動Tweetについて
- 13. 環境
ConoHa VPS CentOS 6.6
標準では ruby-1.8.7
gem install twitter
エラーが出る場合はruby-devel が必要
yum install ruby-devel
- 15. #!/bin/bash
# get hiitcal & tweet URL http://j.mp/hiitcal
script_dir="$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)"
cd $script_dir
test -f basic.ics.2 && mv basic.ics.2 basic.ics.3
test -f basic.ics.1 && mv basic.ics.1 basic.ics.2
test -f basic.ics && mv basic.ics basic.ics.1
wget --quiet --output-document=basic.ics
https://www.google.com/calendar/ical/5udlp7brhcnbuv0mq7t0jcmh04%40group.calendar.google.com/public/basic.ics
test -s basic.ics || { echo "calendar-get-error" ; exit 1; }
test -f basic.lst.2 && mv basic.lst.2 basic.lst.3
test -f basic.lst.1 && mv basic.lst.1 basic.lst.2
test -f basic.lst && mv basic.lst basic.lst.1
cat basic.ics | ./ics2lst.rb | sort > basic.lst
diff basic.lst.1 basic.lst | egrep "^> " | cut -c3- > basic.lst.diff
test -s basic.lst.diff || { exit 0; }
cat basic.lst.diff |
awk '{print "[更新] "$0" #hiitcal http://j.mp/hiitcal"}'
> tweet.lst
if test -s tweet.lst ; then
cat tweet.lst | ./tweetline.rb
fi
hiitcal_tweet.sh
- 16. #!/usr/bin/ruby
# GoogleCalenter(ics) to Textlist
dtstart = ""
description = ""
summary = ""
dtnow = Time.now
dtlocal = dtnow
for line in STDIN
str = line.chomp
case str
when /^DTSTART:20/
dtstarttmp = str.gsub(/DTSTART:/,"")
year = dtstarttmp[0..3]
month = dtstarttmp[4..5]
day = dtstarttmp[6..7]
hour = dtstarttmp[9..10]
min = dtstarttmp[11..12]
sec = dtstarttmp[13..14]
dtgm = Time.gm(year, month, day, hour, min, sec)
dtlocal = dtgm + 60 * 60 * 9
dtstart = dtlocal.strftime("%Y-%m-%d %H:%M")
when /^DESCRIPTION:/
description = str.gsub(/DESCRIPTION:/,"")
when /^ /
description = description + str.gsub(/^ /,"")
when /^SUMMARY:/
summary = str.gsub(/SUMMARY:/,"")
when /END:VEVENT/
if dtlocal > dtnow then
print dtstart," ",summary," ",description,"n"
dtlocal = dtnow
end
end
end
ics2lst.rb
- 17. #!/usr/bin/ruby
# tweet line
require 'rubygems'
require 'twitter'
require 'pp'
sleeptime = 10
@client = Twitter::REST::Client.new(
:consumer_key => "[consumer_key]",
:consumer_secret => "[consumer_secret]",
:access_token => "[access_token]",
:access_token_secret => "[access_token_secret]"
)
for line in STDIN
twstr = line.chomp
@client.update(twstr)
sleep(sleeptime)
end
tweetline.rb
- 20. ツイートする内容
2015-01-16 13:00 [広島]a-blog cms DAY in Hiroshima 2015/01 #ablogcms
https://www.facebook.com/events/768921726527916/?ref=51&source=1
[更新] 2015-01-16 13:00 [広島]a-blog cms DAY in Hiroshima 2015/01 #ablogcms
https://www.facebook.com/events/768921726527916/?ref=51&source=1 #hiitcal http://j.mp/hiitcal
basic.lst.diff
tweet.lst
前日との差分を diff で抽出
diff basic.lst.1 basic.lst | egrep "^> " | cut -c3- > basic.lst.diff
前後に説明やURLをawkで追加
cat basic.lst.diff |
awk '{print "[更新] "$0" #hiitcal http://j.mp/hiitcal"}'
> tweet.lst