Convert or import YAML (or similar) to Google Spreadsheet (or CSV)
I am trying to convert YAML content to google spreadsheet. I am open to different ideas on how to accomplish what I am trying to do ...
Project
Frequently asked Questions
MY REQUIRED DELIVERY
Google Spreadsheet with questions in one column and answers in the next.
MY PROBLEM
I need to deliver content in the specified format. This is stupid. I know this is stupid, so don't get involved here.
I'm not going to write paragraphs of text into a spreadsheet. I hate this.
I prefer to compose the text in a text editor using markdown (or similar). (For previous results, I was able to use a markdown processor with a cobbled script to solve some other problems ...)
Here's the format I'd like to write (and was):
Is this a frequently asked question?:
Yes. People frequently ask this question.
What about this one?:
Not as much. People don't ask that question very frequently.
Et cetera?:
And so forth.
My idea is to run this through some sort of YAML-CSV converter, but I can't seem to find anything that seems to work. (Yes, I googled. No, nothing that appears seems to work.)
PERFECT SOLUTION
A combination of tools or whatever that would allow me to write a little script so that I can go from this to a Google Drive spreadsheet in one step.
OK SOLUTION
I would not mind if the output was a csv file or html table and I had to do some copy and paste or something. I'm also fine with a slightly different layout format.
THIRD PARTY SIGNS
Both questions and answers are English content and use all the usual punctuation marks.
TRAINING IS NOT SUCCESSFUL
The first thing I tried was to write it as if it were a pandoc pipe_tables table, but I hated it.
I have also tried the yaml-to-csv converter at http://codebeautify.org/yaml-to-json-xml-csv , but this results in errors if there are spaces in the yaml keys.
Finally, I tried running sed command to turn my colons and newlines into pipes (or whatever) so that I can use pandoc to create the html table. Nothing about it worked and I ended up replacing all the "r" characters, which was really stupid ...
WHY NOT ONLY COPY AND PAST? (Or - man up and type in dang table)
I have a bunch of these things to do.
It would make me a lot better if I could put together a script or toolset that would allow me to convert and download from a single terminal command.
TL; DR
I need to get from the format of a plaintext key-value pair into two columns of a google spreadsheet in as few steps as possible.
source to share
I solved maybe 90% of my problem with some ruby โโscripts.
require 'yaml'
require 'rubypants'
filename = ARGV[0]
yml = YAML.load_file("./#{filename}.yml")
open("#{filename}.html", 'w') do |f|
f << "<table>"
yml.each do |q, a|
q = RubyPants.new(q).to_html
a = RubyPants.new(a).to_html
f << "<tr><td>#{q}</td><td>#{a}</td></tr>"
end
f << "</table>"
end
This at least gives me a basic html table that I can copy and paste into Google Drive. I also handle Q&A through RubyPants , which gives me some distinctive features that I like.
Due to the specifics of my problem, I'm going to add some header and html style information and a line to open the resulting document in a browser to quickly copy-paste.
I think I'm good if someone doesn't know about an EASY way to get a summary table in Google Docs. (Yes, I know there is an API. If I can figure out how to use it.
---- UPDATE ---- In case anyone is particularly interested, here is my FINAL version. It does the same as above but adds the rest of the HTML document, some styling (so I stay in my preferred display mode - black background) and opens the file in a browser (this part probably only works on mac, which is fine for me).
require 'yaml'
require 'rubypants'
filename = ARGV[0]
yml = YAML.load_file("./#{filename}.yml")
open("#{filename}.html", 'w') do |f|
f << "
<!DOCTYPE html>
<html>
<head>
<style>
body {margin: 20px; font-family: Menlo, Consolas, Arial; color: white; background-color: #222222; }
table {border-collapse: collapse;}
table, td, th { border: 1px solid green; }
td {vertical-align: top; min-width: 500px; padding: 20px; font-size: 24px; line-height: 32px;}
.question { color: #dddddd;}
.answer { color: #efefef;}
h1 { color: #cccccc; }
</style></head><body><h1> #{filename}.html </h1><table>"
yml.each do |q, a|
q = RubyPants.new(q).to_html
a = RubyPants.new(a).to_html
f << "<tr><td class='question'>#{q}</td><td class='answer'>#{a}</td></tr>"
end
f << "</table></body></html>"
end
system("open", "#{filename}.html")
source to share