Skip to content

Instantly share code, notes, and snippets.

@dealingwith
Last active March 30, 2019 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dealingwith/59d49614293bb0bcf98fc1c0d736b822 to your computer and use it in GitHub Desktop.
Save dealingwith/59d49614293bb0bcf98fc1c0d736b822 to your computer and use it in GitHub Desktop.
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