Tip: don’t make it fail completely silently - change this into
if post.nil?
puts "!!! Could not find post #{id}"
return nil
end
Or you will end up wondering why half your posts is missing and after hours of frustration it turns out to be this.
same for these two
next if post.nil?
next if post["deleted"] == "1"