Last active
February 14, 2019 14:41
-
-
Save itsabhinaya/45d4dd77458045bef52897a973dff545 to your computer and use it in GitHub Desktop.
uses the 200wordsaday.com API to export posts details into a CSV
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 posts details into a CSV | |
# to install "gem instal <name>" | |
require 'httparty' | |
require 'date' | |
require "csv" | |
CSV.open("data.csv", "wb") do |csv| | |
csv << ["uuid", "status", "access_rights","slug","datetime","published_datetime","title","word_count","categories","collections","timezone","link"] | |
end | |
url = 'https://200wordsaday.com/api/texts?api_key='+'API_KEY_HERE' | |
response = HTTParty.get(url) | |
entries = response.parsed_response | |
CSV.open("data.csv", "a+") do |csv| | |
entries.each do |entry| | |
csv << [entry["uuid"], | |
entry["status"], | |
entry["access_rights"], | |
entry["slug"], | |
entry["datetime"]["date"].to_s, | |
entry["published_datetime"]["date"].to_s, | |
entry["title"], | |
entry["word_count"], | |
entry["categories"].collect { |item| item['name'] }.compact.join(", "), | |
entry["collections"].collect { |item| item['title'] }.compact.join(", "), | |
entry["timezone"], | |
"https://200wordsaday.com/words/"+entry["slug"] | |
] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment