Skip to content

Instantly share code, notes, and snippets.

@jeffdeville
Created August 19, 2012 19:52
Show Gist options
  • Select an option

  • Save jeffdeville/3397266 to your computer and use it in GitHub Desktop.

Select an option

Save jeffdeville/3397266 to your computer and use it in GitHub Desktop.
Downloads the last 50 pages of Airbrake errors
# Requires mechanize gem (gem install mechanize)
# To use:
# 1. Update this script w/ your site's login url, email, password, and project_id
# 2. gem install mechanize
# 3. ruby download_airbrake_errors.rb
# 4. Wait... I didn't make this thing even remotely fast or efficient, since I don't need to use it that often.
# 5. It will download each error page to the /cache directory
# 6. Search it using your filesystem's built-in search capabilities. The filenames are the ids of the error, so you can easily go to the real site for all of the related links
require 'mechanize'
require 'uri'
PROJECT_LOGIN_URL = "YOUR_LOGIN_URL" # eg: https://[PROJECT_NAME].airbrake.io/login
EMAIL = "LOGIN_EMAIL"
PASSWORD = "LOGIN_PASSWORD"
PROJECT_ID = "PROJECT_ID" # Your site's errors page will look like this: https://[PROJECT_NAME].airbrake.io/projects/[PROJECT_ID]/errors.
m = Mechanize.new
login_page = m.get(PROJECT_LOGIN_URL)
login_form = login_page.form
login_form.field_with(:name => "session[email]").value = EMAIL
login_form.field_with(:name => "session[password]").value = PASSWORD
errors_pages = [login_form.submit]
(1..50).each do |page_num|
errors_pages << m.get("https://packlate.airbrake.io/projects/#{PROJECT_ID}/errors/page/#{page_num}")
end
p "pages loaded"
Dir::mkdir("cache") unless File.exists?("cache")
current_page = 1
errors_pages.each do |page|
p "Current Page: #{current_page}"
error_links = page.links_with(:href => /errors\/(\d)+/).uniq{|link| link.href}
error_links.each do |link|
file_path = "cache/#{link.href.scan(/\d+$/).first}.html"
next if File.exists?("file_path")
page = link.click.save_as "cache/#{link.href.scan(/\d+$/).first}.html"
end
current_page += 1
end
@rogthefrog
Copy link
Copy Markdown

Line 41 did you mean
next if File.exists?(file_path)
or
next if File.exists?("#{file_path}")
?

Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment