Created
December 11, 2012 17:58
-
-
Save jpr5/4260656 to your computer and use it in GitHub Desktop.
Nuke HipChat 1:1 History
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
require 'rubygems' | |
require 'mechanize' | |
account = { | |
:email => "[email protected]", | |
:password => "balls", | |
} | |
agent = Mechanize.new | |
site = agent.post("https://www.hipchat.com/sign_in", account).uri.host | |
# get numeric UID | |
member_id = agent.get("https://#{site}/account"). | |
search('img[alt="Your photo"]').first["src"].match(%r{photos/(\d+)})[1] | |
# determine intervals | |
registered_around = agent.get("https://#{site}/members/#{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 1:1 chats | |
members = agent.get("https://#{site}/history").search("ul.members").children.search("a"). | |
map { |m| m.attributes["href"].value }. | |
reject { |m| m =~ /#{member_id}/ } | |
# walk intervals for each member, capture message_id's | |
messages = {} | |
members.each do |member| | |
intervals.each do |interval| | |
messages[member] ||= [] | |
messages[member] += agent.get("https://#{site}#{member}#{interval}"). | |
search("input[name=message_id]").map { |m| m["value"] } | |
end | |
end | |
messages.each do |member, msg_ids| | |
msg_ids.each do |msg_id| | |
agent.post("https://#{site}#{member}", {:action => "delete", :message_id => msg_id}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lucygeneric : This one does.
https://gist.github.com/lukaszraczylo/11309053