Last active
August 1, 2017 08:05
-
-
Save joshuatobin/8598967 to your computer and use it in GitHub Desktop.
Remove hipchat private chat
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
#!/usr/lib/ruby env | |
# Modified from https://gist.github.com/jpr5/4260656 | |
require 'rubygems' | |
require 'mechanize' | |
account = { | |
:email => "[email protected]", | |
:password => "123456", | |
} | |
agent = Mechanize.new | |
site = agent.post("https://www.hipchat.com/sign_in", account).uri.host | |
# Get our user id | |
member_id = agent.get("https://#{site}/account"). | |
search('img[alt="Your photo"]').first["src"].match(%r{photos/(\d+)})[1] | |
puts "#{member_id}" | |
# Determine our Signup date and the actual date | |
registered_around = agent.get("https://#{site}/people/show/#{member_id}"). | |
search('li:contains("Signed up")').text.sub(/Signed up: /, '') | |
registered_on = Date.parse(`date -d "#{registered_around}"`.chomp) | |
intervals = (registered_on..Date.today).map { |d| d.strftime("/%Y/%m/%d") } | |
# Identify all users ids | |
members = agent.get("https://#{site}/people").search("ul.members").children.search("a"). | |
map { |m| m.attributes["href"].value }. | |
reject { |m| m =~ /#{member_id}/ } | |
messages = {} | |
members.each do |member| | |
puts "#{member}" | |
real_member_id = member.match('/[0-9]*/') | |
puts "real_member_id #{real_member_id}" | |
intervals.each do |interval| | |
puts "#{interval}" | |
messages[real_member_id] ||= [] | |
messages[real_member_id] += agent.get("https://#{site}/history/member#{real_member_id}#{interval}"). | |
search("input[name=message_id]").map { |m| m["value"] } | |
end | |
end | |
# Delete all messages written by us | |
messages.each do |real_member_id, msg_ids| | |
msg_ids.each do |msg_id| | |
agent.post("https://#{site}/history/member#{real_member_id}", {:action => "delete", :message_id => msg_id}) | |
puts "#{msg_id}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment