Created
October 23, 2023 01:56
-
-
Save jordancrawfordnz/c3fb1b0f3b5c363acf31b5fc21a297b1 to your computer and use it in GitHub Desktop.
Fetch and parse Disqus comments
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
# I was struggling to get an export of my Disqus comments because their export feature never provided any results. | |
# I discovered https://blog.jasonantman.com/2014/03/python-script-to-backup-disqus-comments/ (https://github.com/jantman/misc-scripts/blob/master/disqus_backup.py) | |
# which is a Python script to download your Disqus comments. | |
# This script didn't work for me on python3 but I installed python2 and it worked fine. | |
# | |
# Afterwards I had a JSON dump of my comments. I wrote the below script to parse these JSON comments into a CSV | |
# with a thread_link and comment column. | |
# It's not a perfect export format (that's what the JSON is for) but it's good enough for me to read the comments. | |
# | |
# Run with: `ruby parse_disqus_json.rb dump.json export.csv` | |
# Confirmed working on Ruby 3.0.6. | |
require 'json' | |
require 'csv' | |
in_path = ARGV[0] | |
json = JSON.parse(File.read(in_path)) | |
out_path = ARGV[1] | |
comments = json["posts"] | |
threads = json["threads"] | |
comments_by_thread = comments.group_by { |c| c["thread"] } | |
CSV.open(out_path, "wb") do |csv| | |
csv << ["thread_link", "comment"] | |
comments_by_thread.each do |(thread_id, comments)| | |
thread = threads.find { |thread| thread["id"] == thread_id } | |
link = thread["link"] | |
comments.each do |comment| | |
csv << [link, comment["raw_message"]] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment