Skip to content

Instantly share code, notes, and snippets.

@dc1394
Created April 17, 2017 12:49
Show Gist options
  • Save dc1394/0d9c8f1f352e30e01ca1e661db1be94e to your computer and use it in GitHub Desktop.
Save dc1394/0d9c8f1f352e30e01ca1e661db1be94e to your computer and use it in GitHub Desktop.
require 'csv'
require 'json'
require 'net/http'
require 'uri'
def jsontocsv(instance_name)
target_url = 'https://instances.mastodon.xyz/api/instances/history.json?instance=' +
instance_name + '&start=0&end=' + Date.today.to_time.to_i.to_s
parsed = JSON.parse(Net::HTTP.get(URI.parse(target_url)))
csv_filename = instance_name + '.csv'
CSV.open(csv_filename, 'w') do |file|
parsed.each { |item|
file << [Time.at(item['date']).strftime('%Y-%m-%d %H:%M:%S'), item['users'].to_s]
}
end
end
jsontocsv(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment