-
-
Save hyuki/65f1ef8de9417d0fa0642de642f33793 to your computer and use it in GitHub Desktop.
masto-text.rb - とても簡易的にMastodonからエクスポートしたoutbox.jsonをテキスト(Markdown)に変換するRubyスクリプト
This file contains hidden or 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 | |
| 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