Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
200wordsaday.com export script
# uses the 200wordsaday.com API to export your posts as text files
# to install httparty:
# gem install httparty
require 'httparty'
require 'json'
require 'date'
url = 'https://200wordsaday.com/api/texts?api_key=<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
end
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.