Skip to content

Instantly share code, notes, and snippets.

@itsabhinaya itsabhinaya/200wadcsv.rb
Last active Feb 14, 2019

Embed
What would you like to do?
uses the 200wordsaday.com API to export posts details into a CSV
# 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
You can’t perform that action at this time.