When I left Hubski some time ago I deleted my entire comment and post history by hand; this was rude and childish and I would like to apologise for that; it removed content that others had enjoyed and the below script is my attempt to fix that.
This uses ruby and the mechanize gem to login to Hubski and iterate over the deleted page for your user account, credentials are stored in a config file and gems are setup through bundle. This script was for my own purposes and does not have any error handling, but I did include a 2 second delay between items in order to rate-limit it and reduce possible impact to the site as it worked through 940+ items.
Apologies if anybody has been notified from being tagged in the posts -- as these were restorations it was not something I anticipated happening and only now considered.
#Gemfile
source 'https://rubygems.org'
ruby '2.6.3' gem 'mechanize', '2.7.5'
gem 'yaml'
#config.yml
hubski: username: ""
password: ""
#hubski.rb
#!/usr/bin/env ruby require 'mechanize'
require 'yaml'
config = YAML.load_file('config.yml')
@agent = Mechanize.new
@page = @agent.get('https://hubski.com')
# Login to hubski with the saved credentials
@page = @agent.click(@page.link_with(:text => 'login'))
login_form = @page.forms.first
login_form.u = config['hubski']['username']
login_form.p = config['hubski']['password']
@page = @agent.submit(login_form)
puts "Logged in, proceeding to restore"
#A reusable method to find and restore links, with 2 second delay for rate-limiting
def undelete(page, counter)
page.links_with(:text => 'undelete').each do |link|
current_page = @agent.get(link.resolved_uri)
confirmation_form = current_page.forms.first
result = confirmation_form.submit(confirmation_form.button_with(:value => 'No'))
counter += 1
sleep 2
end
counter
end
restore_count = 0
restore_count_total = 0
# Repeatedly check the deleted items list and restore
loop do
@page = @agent.get('https://hubski.com/deleted')
# Restore any comments on the page
restore_count = undelete(@page, restore_count)
# Restore any posts on the page
@page.links_with(:xpath => "//span[@class='feedcombub']/a").each do |link|
post_page = @agent.get(link.resolved_uri)
restore_count = undelete(post_page, restore_count)
end
puts "Restored #{restore_count} posts and comments"
restore_count_total += restore_count
break if restore_count == 0
restore_count = 0
end
puts "Restored #{restore_count_total} total posts and comments, exiting..."
Cool, and welcome back! Thing about formatting: because you didn't escape the + sign in "940+", everything below is bolded. Pluses are for bold in Hubski markdown. Ruby's loop variables in |this format| display as quoted text, so they too need to be escaped with \. Pipes are quotes, two spaces in front of a line make it show explicitly, though I can't even guess how it behaves at times. In general, for code, it's better to just use Gist or pastebin or whatever you fancy. Much less hassle.