Skip to content

Instantly share code, notes, and snippets.

@dealingwith dealingwith/200wad.rb
Last active Mar 30, 2019

What would you like to do? export script
# uses the API to export your posts as text files
# to install httparty:
# gem install httparty
require 'httparty'
require 'json'
require 'date'
url = '<your api key>'
response = HTTParty.get(url)
entries = response.parsed_response
entries.each do |entry|
entrydate = Date.strptime(entry["datetime"]["date"], '%Y-%m-%d').to_s
filename = "files/" + entrydate + "-" + entry["title"].gsub(/[^\w\s]/, '').gsub(" ", "-") + '.txt'
content = entry["content"].
gsub("</p>", "\n\n").
gsub("</blockquote>", "\n\n").
gsub("<blockquote>", " ").
gsub(/<\/?[^>]*>/, "").
gsub(/&nbsp;/, " ").strip
File.write filename, content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.