Last active
April 19, 2022 08:29
-
-
Save pooza/327c16522667f0d3453b4cc61c1c3fb1 to your computer and use it in GitHub Desktop.
EPGStationの録画開始を投稿する、TomatoShriekerプラグイン。
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') | |
require 'tomato_shrieker' | |
module TomatoShrieker | |
class ::Integer | |
def to_time | |
return Time.at(self / 1000) | |
end | |
end | |
http = HTTP.new | |
reserves = {} | |
(JSON.parse(http.get(ARGV.first).body)['records'] || []).each do |row| | |
entry = { | |
'題名' => row['name'].gsub(/\R/, "\n"), | |
'開始' => row['startAt'].to_time.strftime('%m/%d %H:%M'), | |
'終了' => row['endAt'].to_time.strftime('%m/%d %H:%M'), | |
'概要' => row['description']&.gsub(/\R/, "\n"), | |
}.compact.reject {|_k, v| v.is_a?(String) && v.match?(/^\s+$/)} | |
reserves[entry.to_json.adler32.to_i] = entry | |
end | |
path = File.join(Environment.dir, 'tmp/cache/recording.json') | |
File.write(path, reserves.keys.to_json) unless File.exist?(path) | |
ids = JSON.parse(File.read(path)) | |
reserves.each do |id, reserve| | |
next if ids.member?(id) | |
puts reserve.stringify_keys.to_yaml | |
end | |
File.write(path, reserves.keys.to_json) | |
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
entries: | |
- id: recorder | |
source: | |
command: | |
- bundle | |
- exec | |
- ./bin/epg_recording.rb | |
- 'http://192.168.x.x:8888/api/recording?isHalfWidth=false' | |
dir: /home/pooza/repos/tomato-shrieker | |
delimiter: --- | |
dest: | |
account: | |
bot: true | |
hooks: | |
- https://reco.shrieker.net/mulukhiya/webhook/xxxxx | |
schedule: | |
every: 1m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/pooza/loquat に投稿したので、今はメンテしてません。