Created
July 31, 2013 01:59
-
-
Save zph/6118733 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{"month":"7","num":1244,"link":"","year":"2013","news":"","safe_title":"Six Words","transcript":"","alt":"Ahem. We are STRICTLY an Orbiter shop.","img":"http://imgs.xkcd.com/comics/six_words.png","title":"Six Words","day":"29","url":"http://xkcd.com/info.0.json"} |
This file contains hidden or 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
{"month":"1","num":1,"link":"","year":"2006","news":"","safe_title":"Barrel - Part 1","transcript":"[[A boy sits in a barrel which is floating in an ocean.]]\nBoy: I wonder where I'll float next?\n[[The barrel drifts into the distance. Nothing else can be seen.]]\n{{Alt: Don't we all.}}","alt":"Don't we all.","img":"http://imgs.xkcd.com/comics/barrel_cropped_(1).jpg","title":"Barrel - Part 1","day":"1","url":"http://xkcd.com/1/info.0.json"} |
This file contains hidden or 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
{"month":"1","num":2,"link":"","year":"2006","news":"","safe_title":"Petit Trees (sketch)","transcript":"[[Two trees are growing on opposite sides of a sphere.]]\n{{Alt-title: 'Petit' being a reference to Le Petit Prince, which I only thought about halfway through the sketch}}","alt":"'Petit' being a reference to Le Petit Prince, which I only thought about halfway through the sketch","img":"http://imgs.xkcd.com/comics/tree_cropped_(1).jpg","title":"Petit Trees (sketch)","day":"1","url":"http://xkcd.com/2/info.0.json"} |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# | |
require 'json' | |
require 'CSV' | |
require 'open-uri' | |
json_files = Dir.glob("*.json") | |
content = json_files.map do |file| | |
JSON.parse open(file).read | |
end | |
options = { headers: ["safe_title", "transcript", "alt"], col_sep: "~" } | |
CSV.open("output.csv", "w+", options) do |csv| | |
content.each do |row| | |
row_values = [row["safe_title"], row["transcript"], row["alt"]] | |
csv << row_values | |
end | |
end | |
require'pry';binding.pry |
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
This file contains hidden or 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
Six Words~""~Ahem. We are STRICTLY an Orbiter shop. | |
Barrel - Part 1~"[[A boy sits in a barrel which is floating in an ocean.]] | |
Boy: I wonder where I'll float next? | |
[[The barrel drifts into the distance. Nothing else can be seen.]] | |
{{Alt: Don't we all.}}"~Don't we all. | |
Petit Trees (sketch)~"[[Two trees are growing on opposite sides of a sphere.]] | |
{{Alt-title: 'Petit' being a reference to Le Petit Prince, which I only thought about halfway through the sketch}}"~'Petit' being a reference to Le Petit Prince, which I only thought about halfway through the sketch |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# | |
# | |
require 'json' | |
require 'open-uri' | |
require 'pry' | |
nonstandard_url = "http://xkcd.com/info.0.json" | |
# start_url = "http://xkcd.com/1/info.0.json" | |
# end_url = "http://xkcd.com/1243/info.0.json" | |
starting_integer = 1 | |
ending_integer = 2 # 1243 | |
sequential_urls = starting_integer.upto(ending_integer).map do |i| | |
"http://xkcd.com/#{i}/info.0.json" | |
end | |
urls = [nonstandard_url, sequential_urls].flatten | |
content = urls.map do |url| | |
response = JSON.parse open(url).read | |
response["url"] = url | |
response | |
end | |
content.each_with_index do |comic, index| | |
filename = "#{index}.json" | |
puts filename | |
File.write(filename, comic.to_json) | |
end | |
require'pry';binding.pry | |
# take each json | |
# | |
# | |
# | |
# #{"month"=>"7", | |
# "num"=>1244, | |
# "link"=>"", | |
# "year"=>"2013", | |
# "news"=>"", | |
# "safe_title"=>"Six Words", | |
# "transcript"=>"", | |
# "alt"=>"Ahem. We are STRICTLY an Orbiter shop.", | |
# "img"=>"http://imgs.xkcd.com/comics/six_words.png", | |
# "title"=>"Six Words", | |
# "day"=>"29", | |
# "url"=>"http://xkcd.com/info.0.json"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment