Created
June 22, 2017 08:57
-
-
Save vividtone/45785d0bf36358071549134119eeb990 to your computer and use it in GitHub Desktop.
Converts a toot of Mastodon to HTML
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 | |
require 'open-uri' | |
require 'json' | |
require 'time' | |
toot_url = ARGV[0] | |
toot_url =~ %r|^https://(.+?)/@(.*?)/(\d+)$| | |
host = $1 | |
username = $2 | |
status_id = $3 | |
if host.nil? || username.nil? || status_id.nil? | |
STDERR.puts "usage: #{$0} https://mastodon.example.com/@username/status_id" | |
exit 1 | |
end | |
json = open("https://#{host}/api/v1/statuses/#{status_id}").read | |
status = JSON.parse(json) | |
avatar_static = status['account']['avatar_static'] | |
created_at = Time.parse(status['created_at']).localtime.strftime('%Y-%m-%d %H:%M %Z') | |
account_url = status['account']['url'] | |
display_name = status['account']['display_name'] | |
content = status['content'] | |
html = <<EOT | |
<div style="padding:16px 8px;overflow:hidden;border-top:1px solid #888;"> | |
<img src="#{avatar_static}" style="float:left;margin-right:8px;width:48px;height:48px;"> | |
<div style="font-size: 90%; float:right;color:#888;"> | |
<a style="color:#888; font-weight: bold;" href="#{toot_url}" target="_blank">#{created_at}</a> | |
</div> | |
<span style="font-size: 90%; font-weight: bold;"><a style="color: #888;" href="#{account_url}" target="_blank">#{display_name}</a></span> | |
<span style="font-size: 90%; color:#888;">@#{username}</span> | |
#{content} | |
</div> | |
EOT | |
puts html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment