Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
An easy command line tool to clear a PopIt instance
Browse files Browse the repository at this point in the history
  • Loading branch information
martinszy committed Apr 24, 2014
1 parent de7ef47 commit 768281d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions clear_instance
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env ruby
# encoding: utf-8

require 'popit'
require 'optparse'
require 'popit'

##Parse options
options = {}
optparse = OptionParser.new do |option_parser|
option_parser.banner = "Clear a PopIt Instance. Usage: ./clear_instance -u user -p pass -i instance"

option_parser.on("-i n", "--instance=n", "Instance of the PopIt Api on popit.mysociety.org.") do |instance|
options[:instance_name] = instance
end

option_parser.on("-u n", "--user=n", "Api user [USERNAME]") do |user|
options[:api_user] = user
end

option_parser.on("-p n", "--password=n", "Api password [PASSWORD]") do |pass|
options[:api_pass] = pass
end
end
optparse.parse!

##Connect to the API
api = PopIt.new :instance_name => options[:instance_name], :user => options[:api_user], :password => options[:api_pass]

##Delete persons
while (persons=api.persons.get).length > 0 do
puts "Got "+persons.length.to_s+ " persons"
persons.each do |person|
puts "Deleting person "+person["slug"]
api.persons(person["id"]).delete
end
end

while (organizations=api.organizations.get).length > 0 do
##Detele organizations
puts "Got "+organizations.length.to_s+ " organizations"
organizations.each do |organization|
puts "Deleting organization "+organization["slug"]
api.organizations(organization["id"]).delete
end
end

0 comments on commit 768281d

Please sign in to comment.