Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9f2a9a7f7a
Fetching contributors…

Cannot retrieve contributors at this time

executable file 49 lines (37 sloc) 1.612 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#!/usr/bin/env ruby
# Redacts our favourite mega relation

require 'oauth'
require 'yaml'
require 'logger'

# There is one massive relation where every version is by a decliner and
# it's already deleted. However, the expected runtime of the bot is something
# north of a week.

# So lets special-case it somewhat.

ENTITY_ID = 78907
HIGHEST_VERSION = 720
@redaction_id_hidden = 1

auth = YAML.load(File.open('auth.yaml'))
oauth = auth['oauth']

@api_site = oauth['site']

# The consumer key and consumer secret are the identifiers for this particular application, and are
# issued when the application is registered with the site. Use your own.
@consumer=OAuth::Consumer.new oauth['consumer_key'],
                              oauth['consumer_secret'],
                              {:site=>oauth['site']}

@consumer.http.read_timeout = 320

# Create the access_token for all traffic
@access_token = OAuth::AccessToken.new(@consumer, oauth['token'], oauth['token_secret'])

LOG_DIR = 'logs'
log_name = "#{Time.now.strftime('%Y%m%dT%H%M%S')}-#{$$}.log"
@log = Logger.new(File.join(LOG_DIR, log_name))
@log.level = Logger::DEBUG

@log.info("Special mega-relation redaction.")

# Don't include the highest version
(1...HIGHEST_VERSION).each do |version|
  @log.info("Redaction for relation #{ENTITY_ID} v#{version} hidden")
  response = @access_token.post("/api/0.6/relation/#{ENTITY_ID}/#{version}/redact?redaction=#{@redaction_id_hidden}")
  unless response.code == '200'
    @log.error("Failed to redact element - response: #{response.code} \n #{response.body}")
    raise "Failed to redact element"
  end
end
Something went wrong with that request. Please try again.