Skip to content

Instantly share code, notes, and snippets.

@hyuki
Created February 25, 2023 06:47
Show Gist options
  • Select an option

  • Save hyuki/65f1ef8de9417d0fa0642de642f33793 to your computer and use it in GitHub Desktop.

Select an option

Save hyuki/65f1ef8de9417d0fa0642de642f33793 to your computer and use it in GitHub Desktop.
masto-text.rb - とても簡易的にMastodonからエクスポートしたoutbox.jsonをテキスト(Markdown)に変換するRubyスクリプト
#!/usr/bin/env ruby
require 'json'
require 'pp'
require 'time'
def main
if ARGV.length != 1
puts "Usage: masto-text outbox.json"
puts "outbox.json はMastodonでエクスポートしたもの"
puts "簡易的にテキストに変換します。"
abort
end
filename = ARGV[0]
json = IO.readlines(filename).join('')
result = JSON.parse(json)
orderedItems = result['orderedItems']
orderedItems.each do |item|
object = item['object']
published = object['published']
content = object['content']
t = Time.parse(published)
puts
puts "## #{t.getlocal}"
puts content
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment