Last active
March 30, 2019 04:34
-
-
Save dealingwith/59d49614293bb0bcf98fc1c0d736b822 to your computer and use it in GitHub Desktop.
200wordsaday.com export script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(/ /, " ").strip | |
File.write filename, content | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment