This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An easy command line tool to clear a PopIt instance
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
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 |