Last active
May 26, 2023 01:22
-
-
Save pooza/f5ec37af39576447bcdde6fbfb7146ed to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
dir = File.expand_path('..', __dir__) | |
$LOAD_PATH.unshift(File.join(dir, 'app/lib')) | |
ENV['BUNDLE_GEMFILE'] = File.join(dir, 'Gemfile') | |
URL = 'https://timetreeapis.com/calendars/__CALENDAR__/upcoming_events?timezone=Asia/Tokyo&days=7&include=attendees' | |
TOKEN = '__TOKEN__' | |
require 'tomato_shrieker' | |
module TomatoShrieker | |
today = ARGV.first ? Time.parse(ARGV.first).to_date : Date.today | |
uri = Ginseng::URI.parse(URL) | |
http = HTTP.new | |
entries = http.get(uri, { | |
headers: { | |
'Accept' => 'application/vnd.timetree.v1+json', | |
'Authorization' => "Bearer #{TOKEN}" | |
}, | |
})['data'] | |
events = Set[] | |
(0..2).each do |i| | |
date = today.next_day(i).to_date | |
events.merge(entries.select do |entry| | |
date.between?( | |
Time.parse(entry.dig('attributes', 'start_at')).getlocal.to_date, | |
Time.parse(entry.dig('attributes', 'end_at')).getlocal.to_date, | |
) | |
end) | |
end | |
result = events.map do |event| | |
values = event['attributes'].symbolize_keys | |
start_at = Time.parse(values[:start_at]).getlocal | |
end_at = Time.parse(values[:end_at]).getlocal | |
schedule = start_at.strftime('%Y-%m-%d (%a)') if start_at.to_date == end_at.to_date | |
schedule ||= '%s〜%s' % [start_at.strftime('%Y-%m-%d (%a)'), end_at.strftime('%Y-%m-%d (%a)')] | |
[ | |
schedule, | |
values[:title], | |
values[:location], | |
values[:url], | |
values[:description], | |
'#予定', | |
].select(&:present?).join("\n") | |
end | |
puts result.join("\n=====\n") | |
rescue => e | |
warn e.message | |
exit 1 | |
end |
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
source: | |
command: | |
- bin/schedule.rb | |
dir: /path/to/tomato-shrieker | |
schedule: | |
cron: '2 0 * * *' # 深夜0:02 | |
dest: | |
account: | |
bot: true | |
hooks: | |
- https://mstdn.example.com/mulukhiya/webhook/__WEBOOK_HASH__ | |
tags: | |
- 予定 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TimeTreeのスケジュールをリマインドするボット
動作前提
設置手順
schedule.rb
bin/
ディレクトリに置く。URL
は、TimeTreeのカレンダーURLを指定。TOKEN
は「動作前提」時点で取得した、TimeTreeのパーソナルアクセストークン。schedule.yaml
config/sources/
ディレクトリに置く。