Skip to content

Instantly share code, notes, and snippets.

@itsabhinaya
Last active February 14, 2019 14:41
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 itsabhinaya/45d4dd77458045bef52897a973dff545 to your computer and use it in GitHub Desktop.
Save itsabhinaya/45d4dd77458045bef52897a973dff545 to your computer and use it in GitHub Desktop.
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