Toot toooooooot (Bluesky-Mastodon cross-poster)
1class PostHistory 2 HISTORY_FILE = File.expand_path(File.join(__dir__, '..', 'config', 'history.csv')) 3 4 def initialize 5 if File.exist?(HISTORY_FILE) 6 @id_map = File.read(HISTORY_FILE).lines.map { |l| l.strip.split(',') }.then { |pairs| Hash[pairs] } 7 else 8 @id_map = {} 9 end 10 end 11 12 def [](bluesky_rkey) 13 @id_map[bluesky_rkey] 14 end 15 16 def add(bluesky_rkey, mastodon_id) 17 @id_map[bluesky_rkey] = mastodon_id 18 19 File.open(HISTORY_FILE, 'a') do |f| 20 f.puts("#{bluesky_rkey},#{mastodon_id}") 21 end 22 end 23end